Hex-Binary conversion

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

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Hex-Binary conversion

Post by edgore »

I am working on a project that involves parsing some XML that includes file permission information that has been encoded using a bitmask. The bit mask has been converted into hexidecimal for inclusion in the xml files.

What I would like to be able to do is read the xml file and decode the hexidecimal into zeros and ones, from which I can then translate the flipped bits the file permissions.

I have been trying to figure out how to do this using the binarydecode function, but I think I am totally on the wrong track - it is converting the characters to binary, but since I can't figure out how to tell it that the input is hex it's spitting back the 8 bit's that represent the character rather than the 4 bits represented by the hex number that I want...

Is there a way to do this? I am obviously terrible at real computer stuff.
Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark »

Dear edgore,

Please post the relevant part of your script.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith »

As Mark suggests, it's often easier to give good answers when we can se the context, but baseconvert() may be your best bet here...

Code: Select all

put baseconvert(tHexString, 16, 2) into tBitString

If tHexString were 'fc1b', the output would be '1111110000011011'
edgore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 197
Joined: Wed Jun 14, 2006 8:40 pm

Post by edgore »

Sorry for the delay - I ended up just writing a dirty little switch routine that hand converted from hex to binary, since there were only 16 values to deal with.

I looks like baseconvert is what I was looking for though - I will rewrite to use that.

Thansk!
Post Reply