java - Fast way to switch bits order? -
i have binary this
10011011
my data store 10,01,10,11
, want reorder this
11100110
the data 11,10,01,10
.this operation same byteorder convert in bits level.
any fast bitop way ?
currently, have decode 4 int merge one.
the fastest way might precompute table of values:
final int[] values = new int[256]; (int = 0; < 256; ++i) { values[i] = (i & 0b1100_0000) >> 6 | (i & 0b0011_0000) >> 2 | (i & 0b0000_1100) << 2 | (i & 0b0000_0011) << 6; }
and use array lookups rather bit manipulation.
naturally, you'll want profile.
Comments
Post a Comment