Read bit
-
- Posts: 4
- Joined: Fri Feb 24, 2023 11:30 pm
- Been thanked: 2 times
-
- Posts: 18
- Joined: Wed Feb 10, 2021 9:38 am
- Location: Antony,France
- Has thanked: 2 times
- Been thanked: 5 times
Re: Read bit
AND is your best friend!
suppose you want to test the bit b
xxxxbxxx (your variable) apply a mask on it
00001000
AND both value you get
0000b000
so either b is 0 so the result is 0
or b is 1 so the result is not 0
result= value AND (1 << n) will test the nth bit of value (starting from 0 for low bit)
setting a bit to 0
xxxxbxxx
11110111 mask to use with AND
setting a bit to 1
xxxxbxxx
00001000 mask to use with OR
flipping a bit (0->1, 1->0) but don't know the the value
xxbxxxxx
00100000 mask to use with XOR
Hope this is clear.
suppose you want to test the bit b
xxxxbxxx (your variable) apply a mask on it
00001000
AND both value you get
0000b000
so either b is 0 so the result is 0
or b is 1 so the result is not 0
result= value AND (1 << n) will test the nth bit of value (starting from 0 for low bit)
setting a bit to 0
xxxxbxxx
11110111 mask to use with AND
setting a bit to 1
xxxxbxxx
00001000 mask to use with OR
flipping a bit (0->1, 1->0) but don't know the the value
xxbxxxxx
00100000 mask to use with XOR
Hope this is clear.
Tool Kit 1.22
Annex32 WiFi 1.43.2
Windows 10-64b
Firefox 86.0
Serial TeraTerm 4.105
Annex32 WiFi 1.43.2
Windows 10-64b
Firefox 86.0
Serial TeraTerm 4.105