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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -