Hex Value Madness
sling100
Junior Member
Guys
I've got myself stuck with a hex string return from a piece of broadcast kit.
It sends back the elapsed time in HEX, but the values it sends actually represent DECIMAL values
For example.....
Line 330 (12:32:58):: String From [5001:7:1]-[$74$00$49$46$01$00$04]
The actual time is 00h(char 6),01m(char 5),46s(char 4). Note the 46 - not 70 (ie decimal $46)
The only way I can think of presenting each char as 2 digit ascii text for my panels is ...
FORMAT('%02d',ATOI(ITOHEX(cData[4]))) - which seems a bit convoluted to say the least!
I'm sure I'm missing something here, but I haven't seen any daylight for 48 hours and I think it's affecting me a bit!
Thanks
Simon
I've got myself stuck with a hex string return from a piece of broadcast kit.
It sends back the elapsed time in HEX, but the values it sends actually represent DECIMAL values
For example.....
Line 330 (12:32:58):: String From [5001:7:1]-[$74$00$49$46$01$00$04]
The actual time is 00h(char 6),01m(char 5),46s(char 4). Note the 46 - not 70 (ie decimal $46)
The only way I can think of presenting each char as 2 digit ascii text for my panels is ...
FORMAT('%02d',ATOI(ITOHEX(cData[4]))) - which seems a bit convoluted to say the least!
I'm sure I'm missing something here, but I haven't seen any daylight for 48 hours and I think it's affecting me a bit!
Thanks
Simon
Comments
-
Looks right to me... assuming it works, what's the problem? Just make sure you comment it with the expected input format so the next guy (possibly yourself 6 months later) doesn't say "that can't possibly work, I'll fix it"
-
Guys
I've got myself stuck with a hex string return from a piece of broadcast kit.
It sends back the elapsed time in HEX, but the values it sends actually represent DECIMAL values
For example.....
Line 330 (12:32:58):: String From [5001:7:1]-[$74$00$49$46$01$00$04]
The actual time is 00h(char 6),01m(char 5),46s(char 4). Note the 46 - not 70 (ie decimal $46)
The only way I can think of presenting each char as 2 digit ascii text for my panels is ...
FORMAT('%02d',ATOI(ITOHEX(cData[4]))) - which seems a bit convoluted to say the least!
I'm sure I'm missing something here, but I haven't seen any daylight for 48 hours and I think it's affecting me a bit!
Thanks
Simon
This looks to be Binary Coded Decimal, which is actually pretty easy to deal with. See this thread for more information. Basically, you can take the character $46, which has the equivalent integer value of 70 (16 * 4 + 6) and do a modulo operation with 16 to get the ones place, then you can divide the same number by 16 and multiply by 10 to get the ones place.Define_function integer fnDecodeBCD(char bcd){ return (bcd/16 * 10) + (bcd % 16) } define_function char fnEncodeBCD(int bcd){ return (bcd/10 * 16) + (bcd % 10)
Hope that helps. -
Guys
I've got myself stuck with a hex string return from a piece of broadcast kit.
It sends back the elapsed time in HEX, but the values it sends actually represent DECIMAL values
For example.....
Line 330 (12:32:58):: String From [5001:7:1]-[$74$00$49$46$01$00$04]
The actual time is 00h(char 6),01m(char 5),46s(char 4). Note the 46 - not 70 (ie decimal $46)
The only way I can think of presenting each char as 2 digit ascii text for my panels is ...
FORMAT('%02d',ATOI(ITOHEX(cData[4]))) - which seems a bit convoluted to say the least!
I'm sure I'm missing something here, but I haven't seen any daylight for 48 hours and I think it's affecting me a bit!
Thanks
Simon
How about this?
FORMAT('%02X', cData[4])
--D -
Thanks chaps.
My method does work, it just looks a mess - Andrew's BCD function would make it look a lot cleaner for sure.
Dchristo - not sure that would work? Won't that return a hex value? Or maybe that's what I want .... Hmm.
I'm off to have another try!
S
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums