How do I convert HEX to Text?
Chemikal
Posts: 32
Evening,
How do I convert from hexadecimal to text (ascii, ansi)?
Example:
I have "54:78:44:61:74:61:30:41" or "5478446174613041" (no colons)
How do I have the Prop convert that to its equivalent as a string of "TxData0A"?
My favorite site for this as a reference: http://home2.paulschou.net/tools/xlate/
Thanks,
- Josh
How do I convert from hexadecimal to text (ascii, ansi)?
Example:
I have "54:78:44:61:74:61:30:41" or "5478446174613041" (no colons)
How do I have the Prop convert that to its equivalent as a string of "TxData0A"?
My favorite site for this as a reference: http://home2.paulschou.net/tools/xlate/
Thanks,
- Josh
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)
· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBladeProp is: www.bluemagic.biz/cluso.htm
What I do see in another routine is the lookupz command... can I use something like that to form the string? If I can, how would I look through the hex by groups of two?
Else, some other method?
If you need the colons, you'll have to do something more complicated and product 2 hexadecimal digits for each 8 bits of the 32 bit longs and output the colon yourself in the right place. You can still use the "hex" routine and just ask for 2 hexadecimal digits at a time, rotating the 32 bit value left by 8 bits (< -) before calling the "hex" routine each time.
If you're trying to convert an ASCII hexadecimal string to binary, you need the FullDuplexSerialPlus object and you'll need to modify the StrToHex routine to ignore the colons and to produce two 32 bit long values from 16 hexadecimal digits.
I am using XBees, which requires data to be sent in hex as a series of bytes
I have a PHP application that I wrote, which sends various text strings to the Prop through a hardwired serial line, which come from my Google calendar
The strings are the calendar entries, such as "CHE4115: Separation Processes", which the Prop will then send with an attached XBee to a remote Prop with a LCD attached to it
I then need the remote Prop to take those series of bytes it received in the XBee packet, and output it in a LCD compatible format, and I was hoping to use LCD.str(Variable)
Am I on the right track? Any suggestions on what approach I should take?
- Josh
in English:· Each byte is located in a sorted list of the possible hex chars via lookdownz (a very useful command, in other environments you have to test for whether the char is > 9 and adjust for A).· This returns the index 0-15 corresponding to the hex value.· Each output digit is initialized to zero and shifted left 4 before adding the next digit in.· This starts off by shifting some zeroes but leaves our last 4-bit value in the LSB where we want it.
This is also easily extended by changing the repeat 2 to transfer more digits, and instead of the byte operators you could use indeces into byte arrays containing the characters.
On review... it seems you might want to go the other way; that's very similar.· If you have the octets and you want the hex, this is what you do:
The code that does this in fullduplexserial is a bit more terse but I've made this more similar to the other example so hopefully it will be clear how it works.· For each byte we start by masking the high nibble, moving it to the low nibble, then doing the lookup which returns the character at that position in the lookup list.· Then the low nibble is moved to the high nibble before doing it again, so we get the high nibble out first the way humans like to read it.
Post Edited (localroger) : 10/27/2009 12:52:37 PM GMT
You have a PC sending a string to a prop.
The prop with the string - which is a series of bytes terminated by a zero - simply has to send the string via XBee.
On the other side you have a prop which receives this series of bytes which still is a string. You take it and display it, as the display also is happy with a string.
No conversion needed.
Basically, everything is equal, as I understand it, but we're simply changing the human readable format.
ie: $54$78$44$61$74$61$30$41··== "T""x""D""a""t""a""0""A" (will it read as "TxData0A", or will it multiply all the bytes together? Then again, "TxData0A" will equate to a large hex result as if each letter was multiplied together,·yes?)
So I can simply do my qualifications by comparing the hex result to a quoted result (string)?
if HexReceived == "TxData0A" (where HexReceived is the series of hex bytes...)
I will need to look at the transmissions with my logic analyzer, to see how the data is being sent, and then set up some Prop tests to see what different things equate to (such as comparing multiplied hex bytes to strings)
That, and I probably need more coffee... not sure if I am making sense or on the right track.
if strcomp(@HexReceived,string("TxData0A"))
Spin doesn't have string variables. HexReceived would have to be a byte array containing the received data terminated by a zero byte. Look up STRCOMP and STRING in the Propeller Manual.
What a byte means can be anything and it simply depends on where the byte is used. It can be a number which uses all bits or maybe only part of the bits. For example a temperature range from -30 to 50°C ... It might be an ascii character. A sequence of bytes might be a sequence of temperature measurements or a string .... or 3 bytes might be a RGB pixel in a picture. So, you need to know the format of a bytestream for correct handling.
In your case:
Your PHP sends a string, which is a sequence of bytes in ASCII code.
I expect that your XBee object has a function similar to the rx / tx functions of the serial interface. You put in a byte and it will be transmitted.
On the receiver side you receive exactly this byte. The XBee does not care about the meaning of the byte. Nor does it change anything. So, if you send a string on one side you will receive this string on the other side.
And if you received a string you can simply call the print function of the LCD display and is shows this string.
The only problem you might have is the detection of the end of the string. Maybe you have to append a zero in PHP or you use "\n". SPIN functions expect a zero as string terminator.
I will work it out tonight when I am in front of my Prop to further instill my method of attack on this, but I should be all set now.
Thanks again,
- Josh