PDA

View Full Version : Byte Variable modifiers



bugmee
- 12th March 2010, 10:24
Hello,

After looking up modifiers for variables in the manual I saw that there is no way to simply retrieve the lowest 4 bits of a byte, and the highest 4 bits of a byte.

Is this actually available?

If now, what is the easiest way to get the lowest and highest 4 bits of a byte variable?

Thanks

mat janssen
- 12th March 2010, 10:32
And them with %11110000 for the 4 higher bits or and them with %00001111 for the for lower bits.
For the 4 higher bits you could shift them 4 times right to get them on the lower positions

Byte_Butcher
- 12th March 2010, 15:26
Use the bitwise operator "&" like this:



mynibble = mybyte & %00001111 'Put the lower 4 bits into mynibble

myothernibble = mybyte & %11110000 'Put the upper 4 bytes into myothernibbe


steve


Dohh! Mat beat me to it. :)

misamilanovic
- 12th March 2010, 16:27
You could do this:


highbits = yourbyte / 16
lowbits = yourbyte // 16