Forum Discussion
Converting Hex to Binary function to detect on/off state
I am receiving data for the operation of some sensors which is in Hex format.
In order to see which sensor is on and which is off, I need to convert this into Binary, thus know which sensors are on or off.
example: I get
| 0xc00000200 |
| 0x1000000 |
| 0x400000 |
| 0x500000000 |
0x400040000 |
0x0 |
Each row of the Hex after 0x at full length must be of 12 characters, so:
0x0 = 0x000000000000
0x400040000 = 0x000400040000
etc...
the results might be something like:
0000 0000 0000 1010 0000 0000 0000 0000 0001 0000 0000 0000
where each character of the binary represents a sensor.
When the HEX is converted to Binary like above. How am i going to define the name of each of the character in the binary?
so if 0000 0000 0000 1010 ...... I would be able to reverse it and give each of the binary character a name like B1, B2, B3 ... B48.
Hope someone has a good solution to this, thanks :)
3 Replies
- AnonymousNot applicable
I guess it is too hard to calculate, since no one has answered
- dax
Community Support
Hi Alisina,
It seems that you want to convert HEX to Binary, right? There is no direct function to achieve this goal. You might need to convert this to number, then convert this to Binary. You could refer to convert from hexadecimal value to number and Number to Binary for details.
In addition, if you want to format it, you could use my below expression
Column = IF ( 14 - LEN ( hex[c1] ) = 14, hex[c1], REPLACE ( hex[c1], 1, 2, MID ( "0x000000000000", 1, 14 - LEN ( MID ( hex[c1], 3, LEN ( hex[c1] ) - 1 ) ) ) ) )Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Thanks for trying :)
I was hoping for a way to convert to binary and be able to say binary number 5 from 0000 1001 0000 .... has 1 meaning it is on (counting from left). Binary number 8 is also active etc...
So I can point to the data at hand without having to split it etc.