-
hexadecimal char to int.
how can I transfer a char[] holding an hex value (something like : "FFFAFF88" ) into a simple int?
I already made one to transfer decimal char into int but hex im kinda clueless..
Dont tell me to use another function held in some library I wanna make my own using only <iostream> if possible.
thx
Luigi
-
Well, if you have already done a decimal version, then you're halfway there. Hex numbers are base 16. So if you have a number like "FF", the one's place contains 15, and the sixteen's place contains 15...so 16*15 + 1*15 = 255, or 0xFF.
0xA3F = (16*16)*10 + 16*3 + 1*15 = 2623
gg
-
You can modify the FAQ example to do the work for you, if you want.
Or, if you don't want stringstreams, try strtol() as per this FAQ example
But which every way you choose, FFFAFF88 might not fit into a simple int due to size limitations.
-
I wrote a function a while back that converts between bases 2-36.
-
Whoops! Forgot to attach it.