I need more Bits.

Hooter

Senior Member
Folks - I am using an 08M2 and I understand that there are 32 bit variables available - as stated in Manual 2:

b0 = bit7: bit6: bit5: bit4: bit3: bit2: bit1: bit0
b1 = bit15: bit14: bit13: bit12: bit11: bit10: bit9: bit8
etc...

My program requires up to about 48 bit variables to be controlled like this code snippet:

Code:
if bit29 = 0 then pulsout c.4,5
else pulsout c.2,5
endif
if bit28 = 0 then pulsout c.4,5
else pulsout c.2,5
endif
if bit27 = 0 then pulsout c.4,5
else pulsout c.2,5
endif
if bit26 = 0 then pulsout c.4,5
else pulsout c.2,5
endif
if bit25 = 0 then pulsout c.4,5
else pulsout c.2,5
endif
if bit24 = 0 then pulsout c.4,5
Would peek and poke allow me to do the same as above or is there a better method available or perhaps a different Picaxe chip.
Any suggestions are always appreciated.
 

hippy

Technical Support
Staff member
A common trick is to move byte variables into b0 then use bit0 through bit7. For example -

b0 = b1
If bit0 = 1 Then B1_Bit0_Set
If bit1 = 1 Then B1_Bit1_Set
b0 = b2
If bit0 = 1 Then B2_Bit0_Set
If bit1 = 1 Then B2_Bit1_Set
 

westaust55

Moderator
Another option is to use the AND math function to mask so that you can check indivdual bits in any byte.
For example, say you are using the 8 bits in byte variable b5 then for the lower 3 bits:

Code:
Bit0 = b5 AND $01 ; mask off to keep only bit0 in b5
IF Bit0 = 0 THEN
  ; Byte 5 Bit0=0 so do something
ELSE
  ; Byte5 Bit0=1 so do something else
ENDIF
Bit0 = b5 AND $02  ; mask off to keep only bit1 in b5
IF Bit0 = 0 THEN
  ; Byte 5 Bit1=0 so do something
ELSE
  ; Byte5 Bit1=1 so do something else
ENDIF
Bit0 = b5 AND $04  ; mask off to keep only bit2 in b5
IF Bit0 = 0 THEN
  ; Byte 5 Bit2=0 so do something
ELSE
  ; Byte5 Bit2=1 so do something else
ENDIF
 
Top