Shop OBEX P1 Docs P2 Docs Learn Events
Check-sum using xor ^ — Parallax Forums

Check-sum using xor ^

L_GamindeL_Gaminde Posts: 29
edited 2013-07-07 12:39 in BASIC Stamp
I am trying to make a list of check-sum values the code below works great but how do I get A through F into the variable a after it runs through 1 through 9


' {$STAMP BS2}
' {$PBASIC 2.5}
a VAR Word
b VAR Word
z VAR Word
start:
FOR a = 48 TO 57
FOR b = 48 TO 57
z = 59 ^a ^b ^78
DEBUG a,b," ",a,b,"N",HEX z,CR
PAUSE 500
NEXT

FOR b = 65 TO 70
z = 59 ^48 ^b ^78
DEBUG a,b," ",a,b,"N",HEX z, CR
PAUSE 500
NEXT
NEXT

END

Comments

  • L_GamindeL_Gaminde Posts: 29
    edited 2013-07-07 11:02
    Well this is what I came up with!
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    a VAR Word
    b VAR Word
    z VAR Word

    start:
    FOR a = 48 TO 57
    FOR b = 48 TO 57
    z = 59 ^a ^b ^78
    DEBUG a,b," ",a,b,"N",HEX z,CR
    PAUSE 500
    NEXT

    FOR b = 65 TO 70
    z = 59 ^48 ^b ^78
    DEBUG a,b," ",a,b,"N",HEX z, CR
    PAUSE 500
    NEXT
    NEXT

    FOR a = 65 TO 70
    FOR b = 48 TO 57
    z = 59 ^a ^b ^78
    DEBUG a,b," ",a,b,"N",HEX z,CR
    PAUSE 500
    NEXT

    FOR b = 65 TO 70
    z = 59 ^48 ^b ^78
    DEBUG a,b," ",a,b,"N",HEX z, CR
    PAUSE 500
    NEXT
    NEXT


    END
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-07-07 11:20
    Larry, not sure if this does what you want. It runs the a and b variables from 48 to 63, but translates the values from 58 to 63 up to "A" to "F".
    [SIZE=1][FONT=courier new]a VAR BYTE
    x VAR BYTE
    b VAR BYTE
    y VAR BYTE
    z VAR WORD
    FOR a=48 TO 63
      IF a>57 THEN x=a+7
      FOR b=48 TO 63
        IF b>57 THEN y=b+7
        z = 59 ^ x ^ y ^ 78
        DEBUG x,y," ",x,y,"N",HEX z,CR
        PAUSE 500
      NEXT
    NEXT
    [/FONT][/SIZE]
    

    The bitwise xor operation is commutative, so I think you can replace the 59^78 with one ^117.
  • L_GamindeL_Gaminde Posts: 29
    edited 2013-07-07 11:39
    Yes i think this is what i wanted, i changed the x and y to a and b so it would print out from 00 to FF
    thanks Tracy I think this is the first thing you posted for me that I did not have to look at for a few hours to understand. after 10 years I'm still trying to figure out your Julian stuff.

    SO is there a way to print out the Debug list?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    a VAR Byte
    x VAR Byte
    b VAR Byte
    y VAR Byte
    z VAR Word
    FOR a = 48 TO 63
    IF a > 57 THEN a = a + 7
    FOR b = 48 TO 63
    IF b > 57 THEN b = b + 7
    z = 59 ^ a ^ b ^ 78
    DEBUG a,b," ",a,b,"N",HEX2 z,CR
    PAUSE 100
    NEXT
    NEXT
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2013-07-07 12:30
    Hmmm. I'd think that adding 7 to the actual loop variable would mess up the loop execution. That's why I threw in x and y.

    The value of z is the only one being printed out as 00 to FF.

    Print out the debug list--Capture the list using a terminal program, Putty, CoolTerm, Hyperterminal etc. Then print the text file.

    (Ah, Julian time is quite a numbers game!)
  • L_GamindeL_Gaminde Posts: 29
    edited 2013-07-07 12:39
    yea ok I lied! it is going to take some time :)
    yours starts at AA and goes to FF but skips the lower set 00 to 9F because of the X-Y in the debug statement so I need to implement you thinking into something a little different.
Sign In or Register to comment.