Need help with Subroutine
MovieMaker
Posts: 502
OK, here is what I need to do.· I am not a mathmatician, but here goes:
I want to have a 16 bit binary number. I want to store it somewhere , maybe eprom.
I want to be able to read anyone of the 16 bits.
I want to be able to write to anyone of the 16 bits.
How would I MASK individual bits in order to do this?
I need to know how to isolate each individual bit.
I am not knowlegable in this area.
Thanks!
·
I want to have a 16 bit binary number. I want to store it somewhere , maybe eprom.
I want to be able to read anyone of the 16 bits.
I want to be able to write to anyone of the 16 bits.
How would I MASK individual bits in order to do this?
I need to know how to isolate each individual bit.
I am not knowlegable in this area.
Thanks!
·
Comments
You can also access these individual bits as if they were a bit array like: FOO.BIT0(i)
Say you want to access bit 6. You'll make a mask like the following:
mask = %0000000001000000
Where the bit that you want to access (6) is denoted by a 1 in the above mask. Then you AND that with your number:
result = my_num & mask
If result is zero, then then it's a 0 in that position, otherwise it's a 1.
You'd use just the reverse to write to that position:
mask = %1111111101111111
my_num = my_num & mask
Clears that bit
mask = %0000000001000000
my_num = my_num | mask
Sets that bit high.