Expert Answer:
s:
You need bin2dec
and bitget
.
The code, you need to use is bitget(a,2)
rather then getbit
, and its little endian, so its looking from the right, meaning bit number 2 will return 0
Updating answer to updated question: again, you still need to be using the bitget
command, and it is NOT looking at the bits from the left, it is looking at them from the right.
For example if your bits were a=11110000
:
bitget(a,1) = 0
bitget(a,2) = 0
bitget(a,3) = 0
bitget(a,4) = 0
bitget(a,5) = 1
bitget(a,6) = 1
bitget(a,7) = 1
bitget(a,8) = 1
I hope this helps