
1. Re: How do you convert hexadecimal to binary?
BKBK Apr 12, 2012 11:43 AM (in response to Krandolph)The set of functions you want is: inputBaseN, formatBaseN. For example,
<cfset myHex = "1DD630000C0E1012">
<cfset myHexInBase10 = inputBaseN(myHex,16)>
<cfset myHexInBase2 = formatBaseN(myHexInBase10,2)>
<cfoutput>
<h2>
myHex = #myHex#<br />
myBinary = #myHexInBase2#
</h2>
</cfoutput>
However, I did use a smaller hex. It seems your original number is larger than ColdFusion's range.

2. Re: How do you convert hexadecimal to binary?
Krandolph Apr 12, 2012 1:03 PM (in response to BKBK)Hello,
Thanks. That helped tremendously. The good news is that it came to my attention after your reply, that we really only need to parse part of the hex value, so this works out fine. The other news is that it looks like I then have to convert the binary value to 8bit decimal.
How would I go about that part?
Best regards,
KR

3. Re: How do you convert hexadecimal to binary?
==cfSearching== Apr 12, 2012 1:33 PM (in response to Krandolph)Can you give an example of the expected results?

4. Re: How do you convert hexadecimal to binary?
Krandolph Apr 12, 2012 1:46 PM (in response to ==cfSearching==)Hello,
The part of the hex I need (1DD63), converts to 10111010 in binary. That in turn converts to 186 in 8bit decimal. I don't know have a clue what ColdFusion function to use to go from the binary string to the 8bit decimal.
Now that I know that the final value I need is a 8bit decimal value, does it make more sense to just convert from 1DD63 directly to 186? So just convert straight from HEX to the 8bit decimal value?
This is all way out of my normal depth, so any help is appreciated.
Best regards,
KR
01001001 00100000 01101000 01100001 01110100 01100101 00100000 01100010 01101001 01101110 01100001 01110010 01111001 0100001 sums up my feelings on binary.

5. Re: How do you convert hexadecimal to binary?
==cfSearching== Apr 12, 2012 3:23 PM (in response to Krandolph)So just convert straight from HEX to the 8bit decimal value?
Well "1DD63" does not convert to 186 directly. It really depends on the packet itself and the decoding instructions you were given. It might be as simple as using input/formatBaseN, or you might need extra code, depending on how many values and what you are ultimately decoding. (That is not clear from the original question). Exactly what were the instructions about the string's composition and extraction of the values?
sums up my feelings on binary.
Lol, you are not alone in that.
Message was edited by: ==cfSearching==

6. Re: How do you convert hexadecimal to binary?
Krandolph Apr 12, 2012 4:00 PM (in response to ==cfSearching==)Hello,
The starting hexadecimal packet is '01DD6300000C0E1012'. The part that I contains the data I need is in the first batch of characters. The instructions I was given was that the first 6 characters (less the first character) contained the part that I want.
So, my code is now
<cfset myBaseHex = "01DD6300000C0E1012">
<cfset myHex = mid("01DD6300000C0E1012",2,5)>
<cfset myHexInBase10 = inputBaseN(myHex,16)>
<cfset myHexInBase2 = formatBaseN(myHexInBase10,2)>
<cfoutput>
<h2>
myHex = #myHex#<br />
myBinary = #myHexInBase2#
</h2>
</cfoutput>
The next step was to convert the binary part to 8bit decimal. The person that gave me the data, said that this particular one should resolve to 186.
Best regards,
KR
01001001 00100000 01101000 01100001 01110100 01100101 00100000 01100010 01101001 01101110 01100001 01110010 01111001 0100001 sums up my feelings on binary. I'm glad that at least one person found some humor in my binary :)

7. Re: How do you convert hexadecimal to binary?
==cfSearching== Apr 12, 2012 6:23 PM (in response to Krandolph)Not to state the obvious, but there is something missing from this equation. Because AFAIK, 1DD63 does not convert to 10111010 (or 186) in binary. Not even if you break the int into four bytes.
Are those the only instructions they gave you about the string and its format?

8. Re: How do you convert hexadecimal to binary?
BKBK Apr 13, 2012 12:29 AM (in response to Krandolph)Krandolph wrote:
convert the binary value to 8bit decimal.
Remember that 8bit decimal is a compound expression. It contains two concepts: 8bit and decimal.
In standard notation, it means an integer which is in the interval [0,255] when converted to base 10. For example, 256 is out of the range, and so is no 8bit number. Unless of course we allow a cyclic rotation modulo 256, whereby 256 reverts to 0, 257 to 1, and so on.
The base 16 number 1DD63 is much larger than 255 when converted to base 10. It is in fact 122211 in base 10, and is therefore not 8bit. Also, even if you rotate it cyclically modulo 256, you will arrive at 99, which doesn't match any of the numbers you've given.
Starting from other angles, the base 16 number 1DD63 converts to 11101110101100011 in binary. The decimal number 186 converts to BA in hexadecimal, not to 1DD63 as you suggest.
You can already tell, without doing any calculation at all. The bases 2, 10 and 16 are all even. So, if you convert an odd number from any of the bases to another, it must end in an odd integer. Likewise, if you convert an even number from any of the bases to another, it must end in an even integer. This enables you to immediately rule out any eventoodd or oddtoeven conversions.

9. Re: How do you convert hexadecimal to binary?
Krandolph Apr 16, 2012 8:32 AM (in response to BKBK)Hello,
Thanks for the help. After you said that the number doesn't convert directly over, a coworker rechecked the other guys stuff and found that he was over thinking the issue. The value we wanted was actually directly in the binary.
Best regards,
KR

10. Re: How do you convert hexadecimal to binary?
==cfSearching== Apr 16, 2012 2:56 PM (in response to Krandolph)Thanks for the help. After you said that the number doesn't convert directly over, a coworker rechecked
the other guys stuff and found that he was over thinking the issue. The value we wanted was actually directly in the binary.
Good, that makes a lot more sense :)

11. Re: How do you convert hexadecimal to binary?
BKBK Apr 17, 2012 12:44 AM (in response to Krandolph)Krandolph wrote:
Hello,
Thanks for the help. After you said that the number doesn't convert directly over, a coworker rechecked the other guys stuff and found that he was over thinking the issue. The value we wanted was actually directly in the binary.
Marking this as the answer misinforms the forum. What's this got to do with your original question,"How do you convert hexadecimal to binary?".