how to convert hexadecimal unsigned charcter into binary number in c
Answers
Answer:
I'm trying to convert unsigned chars to their hex ASCII values but in binary form. For example: unsigned char C to 0100 0011 (43) I can get from ...
yes bro I know about it this is cimputer answer
There are many ways to solve this question that use some arithmetics to convert from ascii character ranges 0-9 and a-f (or A-F) to binary. I wanted to find a solution which only uses a lookup table and benchmark that against a solution that uses arithmetics instead. Strangly enough, none of the answers above implement a purely arithmetic solution and some answers even assume that "converting to binary" means converting to a ascii string of characters "0" and "1".
Lets first do some setups. Firstly, we want to have the whole test data in memory so that we avoid disk I/O influencing the test. Here is how I create a header with a character array "testdata" of 104857600 bytes, roughly 105 MB. As the question was how to convert files, our implementation should be fast on large data.
$ { printf "char *testdata =\""; cat /dev/urandom \
| tr -d -c "0123456789abcdefABCDEF" \
| dd count=100 iflag=fullblock bs=1M; printf "\";\n" } > testdata.h
bhai ye sab maine book main pada tha thodi help book se li or baki ka maine hi kiya hai
brainlist mark nahi karo to thanks hi dena bhai please