I am trying to decode a supposedly hex string. In MS SQL Server (11.0.2100) the data has the type of char(8)
.
In the manuals there was no clear way of decoding the data but it documents what it contains:
Given a hex string ie.
0001003F
with a length of 4. The lower byte is on the right, the higher byte is on the left. For each of the 4 'bytes
' a reference table that maps a 'bit' to a certain truthy value was given. A bit order is also given having the bit 0 or the bit in right most being the 1st bit, ..., etc.
The table looks like this:
1st 'byte':
|Bit Order | Description | 1 | 0 | trigger |
|-----------|---------------|-------------------|-------------------|---------------|
|BIT0 | state foo | state foo is ON | State foo is OFF | high level |
|BIT1 | state bar | in state bar | not in state bar | high level |
| ...
|BIT7 | state bazz | in state bazz | not in state bazz | high level |
(3 more tables follows for the next 3 other 'byte's ..., each of the 4 'byte's supposedly has 8 equal number of 'bits')
I thought the way of decoding this data is to split the hex string into 4 parts and convert them into a binary string width a fixed with of 8.
In PHP
, taken the example hex '0001003F
', the first byte was '3F
', having the converted to binary, 0011 1111
(space for clarity). Then, inferred that the value for the first byte was:
'state foo is on', 'in state bar', ..., 'not in state bazz'
.
I also tried to do: hex2bin("0001003F")
but it outputs strin(4) " # "
.
Is this the correct way of decoding this data?
(I beg your pardon if the tags are incorrect.)