Shop OBEX P1 Docs P2 Docs Learn Events
Formating Question — Parallax Forums

Formating Question

JomsJoms Posts: 279
edited 2008-11-14 05:09 in BASIC Stamp
I am attempting to convert the decimal format of a variable into two separate hex digits...· please see example below...
Dest····· VAR···· Byte
Dest = 24 (18 as a hex, or $18)
Now I need to look at the hex as if it was a character and convert those characters to two hex digits....
1 as a character = 31 as a hex, and 8 as a character = 38 as a hex...
Now I want to debug the data as:· ·31 38
Eventually I want to output that data as part of a serial string...
I just can't seem to figure out the character part of the formatting...· Thanks in advance for any help....

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-11-14 04:09
    Hi, this seems a little cumbersome and there may be a better way but it should work

    If Dest.HighNib>9 Then
    Factor=55
    Else
    Factor=48
    Endif
    Byte_1 = Dest.HighNib+Factor
    If Dest.LowNib>9 Then
    Factor=55
    Else
    Factor=48
    Endif
    Byte_2=Dest.LowNib+Factor
    DEBUG Hex2 Byte_1," ",Hex2 Byte_2

    Jeff T.
  • JomsJoms Posts: 279
    edited 2008-11-14 05:09
    WOW!!! IT WORKS!!! After many hours that actually did what I wanted it to do... It is kinda long because I am doing it 6 times for three different sets of numbers but at least it gets the right numbers. Thanks for your help Unsoundcode!!! Do you, or anyone else know of a way I could cut the code down because I have to do it several times? I will post the code tomorrow so you have an idea of what is going on. I am thinking maybe I can use a FOR loop or something...
Sign In or Register to comment.