test on specific bit in a variable
Bobb Fwed
Posts: 1,119
In PBASIC, is there any simple way to see what a specific bit is in a variable. SPIN uses "|<" syntax. Anything along those lines?
I have a nibble decimal variable, each bit represents a different setting. I have it all as one variable so I can output to the user a 9 rather than 1001 (I am limited to the number of displayed characters.
I have a nibble decimal variable, each bit represents a different setting. I have it all as one variable so I can output to the user a 9 rather than 1001 (I am limited to the number of displayed characters.
Comments
it works great for checking and also setting a bit in a byte, when you want to do it in a loop etc...
thisbit var bit
thatbyte var byte
'TO·CHECK THE VALUE OF A BIT LOCATION IN A BYTE
thisbit = thatbyte.bit0(n)············ 'where·n is the bit location in the byte ie: 0 - 7
'TO·SET THE VALUE OF A BIT LOCATION IN A BYTE
thatbyte.bit0(n) = thisbit············ 'where·n is the bit location in the byte ie: 0 - 7
cheers,
Chris, West Oz