java - Set bit values in Byte -
java - Set bit values in Byte -
i need set bit of bluetooth features listed below using java:
headervalue:bluetoothfeatures, tag id:0x10, length:4 bytes, possible values : bit 0 = a, bit 1 = b, bit 2 = c, bit 3 = d, bit 4 = e ....so on till bit 31.
to set 7th bit 1:
b = (byte) (b | (1 << 6));
to set 6th bit zero:
b = (byte) (b & ~(1 << 5));
(the bit positions 0-based, that's why "seventh bit" maps 1 << 6 instead of 1 << 7.)
source : change bits value in byte
java
Comments
Post a Comment