PDA

View Full Version : Bit Masking and Or?



dbachman
- 24th February 2009, 05:39
How do I convert from a 4 bit number such as x = 0110

to an 8 bit number such as x = 00100110

Do I:

-----0110
00001111 And
---------
00000110


00000110
00100000 OR
---------
00100110 Result



Thanks, Don

Archangel
- 24th February 2009, 05:47
4 bit number . . . you trying to convert code from Stamp?
x = 0110 is I believe the same as x = 00000110 and same as 6 and same as $06. There are no nibble variables in PBP you have to use the whole byte. So MyVar Var NIB becomes MyVar VAR BYTE.

dbachman
- 24th February 2009, 05:56
Hi Joe,

So....

Data @0 , 6

read 0, x

Would the variable x be equal to 00000110b

so then to make it 00100110 I would OR it with 00100000?


Thanks, Don

Archangel
- 24th February 2009, 06:26
http://en.wikipedia.org/wiki/Bitwise_operation
I am not a MATH Guy, but I believe in the example you listed, a bitwise OR would do that. Here is a link with some info. Or cannot you just add the 32 to six ?

mister_e
- 24th February 2009, 16:19
with PBP, 4 Bit number don't exist. I know STAMPs have Nibble variable, but not in PBP. You have Bit, BYTE, and WORD. So you could use OR or just directly set the bit you want

ByteA = %110
ByteA.5=1

should do the trick as well.