Hey everyone. Quick question. Say I have a hex string = "6c". I want to be able to turn that into a bit representation of 0000 0000. would i have to convert it to a integer first then do some sort of left shift on it?? Thanks.
bitwise operations.
Collapse
X
-
The next step is to create a string that represents a binary representation of the number. The *printf family of functions can't help you (they only do octal, decimal or hexadecimal representations of a number). A bit of bit shifting can do the job though.
kind regards,
Jos -
In the context if what JosAH has said
The following algotithm will perform the transformation also.
1. make the 4 LH bits equal to the LH hex numeral or letter.
2. make the next 4 bits equal the next hex numeral or letter
3. repeat 2 above until the hex integer is exhausted.
e.g. convert 0x 5 d 2 3 f a
bin equivalent is 0101 1101 0010 0011 1111 1010
hth'sComment
-
I find it hard to believe that you are recommending using a *scanf function Jos, I personally have always believed that they are a curse on the C language.
Myself I would use strtol
kind regards,
JosComment
Comment