Converting Hex to ASCII

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

Converting Hex to ASCII

Post by keithglong » Sat May 21, 2016 12:28 am

Hi All,

I am trying to convert Hex to ASCII, similar to the Hex to ASCII Text Converter at:

http://www.rapidtables.com/convert/numb ... -ascii.htm

When I enter 57612be9 and click on the "Convert" button, I get the following value:

Wa+é

Using the binaryEncode function in LiveCode...

Code: Select all

answer binaryEncode("H*", "57612be9")
I get Wa+È

Any idea as to why that last character is off? Any feedback would be most welcome.

Thanks!

Sincerely,

Keith "Boo" Long
Gulf Breeze, Florida

Ledigimate
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 132
Joined: Mon Jan 14, 2013 3:37 pm

Re: Converting Hex to ASCII

Post by Ledigimate » Sat May 21, 2016 6:10 am

Hi Keith

The last 2 hex digits correspond to the 233rd character of the Extended ASCII Character set, which may vary on different platforms and computers for several reasons. The web calculator most likely uses a different Extended ASCII Character set from that used by LiveCode on your computer.

However, you can be fairly confident that the actual *binary* value would be the same across all platforms. The difference comes in when the binary value is converted to text.

Here's a Wikipedia article explaining how such differences can be commonplace:

https://en.wikipedia.org/wiki/Extended_ ... _confusion

Kind regards,

Gerrie
010100000110010101100001011000110110010100111101010011000110111101110110011001010010101101010100011100100111010101110100011010000010101101001010011101010111001101110100011010010110001101100101

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Converting Hex to ASCII

Post by bn » Sat May 21, 2016 9:15 am

Hi Boo,

ASCII 233 for Win/ISO is é
ASCII 233 for Mac is È

Apparently you are using a Mac and LC returns the Mac ASCII value

if you force LC to interpret ASCII 233 as ISO by using isoToMac it will translate to é

Code: Select all

answer isoToMac(binaryEncode("H*", "57612be9"))
a bit confusing.

I looked here:
http://academic.evergreen.edu/projects/ ... xt-mac.htm
http://academic.evergreen.edu/projects/ ... ext-pc.htm

Kind regards
Bernd

keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

Re: Converting Hex to ASCII

Post by keithglong » Thu May 26, 2016 5:25 pm

Thanks guys!
However, you can be fairly confident that the actual *binary* value would be the same across all platforms.
Correct.

Warmest regards,

- Boo
Gulf Breeze, Florida

Post Reply