How to convert a hexadecimal char into a 4-bit binary representation?
<p>I wish to compare a SHA-256 hash which is stored in u8[32](after being calculated in kernel-space) with a 64 char string that the user passes as string.</p>

<p>For eg. : User passes a SHA-256 hash "49454bcda10e0dd4543cfa39da9615a19950570129420f956352a58780550839" as char* which will take 64 bytes. But this has to be compared with a hash inside the kernel space which is represented as u8 hash[32].</p>

<p>The hash inside the kernel gets properly printed in ASCII by the following code:</p>

<pre><code>int i;
u8 hash[32];

for(i=0; i&lt;32; i++)
    printk(KERN_CONT "%hhx ", hash[i]);
</code></pre>

<p>Output : 
"49 45 4b cd a1 0e 0d d4 54 3c fa 39 da 96 15 a1 99 50 57 01 29 42 0f 95 63 52 a5 87 80 55 08 39 "</p>

<p>As the complete hash is stored in 32 bytes and printed as 64 chars in groups of 2 chars per u8 space, I assume that currently one u8 block stores information worth 2 chars i.e. 00101111 prints to be 2f.</p>

<p>Is there a way to store the 64 bytes string in 32 bytes so that it can be compared?</p>