Stuck with variables

JoePage2008x2

New Member
Say i set w0 to equal 54321, how would i set b2 to equal 5, b3 = 4, b4 = 3, etc.. It would be very much appreciated if anyone can help me
 

QuIcK

Senior Member
this can be done with the command DIG on X1 and X2 parts only.
for example:
Code:
w0 = 54321
b2 = w0 DIG 4 '5
b3 = w0 DIG 3 '4
b4 = w0 DIG 2 '3
b5 = w0 DIG 1 '2
b6 = w0 DIG 0 '1
See BASIC commands page 22
 

westaust55

Moderator
Another option (not restricted to the X1/X2 parts) is to consider the BINTOASCII command (See latest PICAXE Manual 2 (currently rev 6.8) page 29

BINTOASCII wordvariable, tenthousands, thousands, hundreds, tens, units
This will break out the digits but as ASCII values. (ASCII values are those encoded ready to send to say an LCD display)
To get from ASCII to actual value, for each digit subtract $30 (decimal 48)


For the previously mentioned DIG command see bottom of page 20 and also page 22
 
Last edited:
Top