Search code examples
c#nibble

Convert a string of hexadecimal characters to an array of nibbles (interview experience)


I have seen this question unanswered in an interview experience

first of all, I need to understand the question,

(a nibble corresponds to single hex character right?) so, if given Hex string "12A" then the output should be

arr[0]=0001
arr[1]=0010
arr[2]=1010

is that correct or have i misunderstood?

if so how do i go about implementing this in C#? whats the type of arr here?


Solution

  • A nibble is a four bit binary. As such you need three nibbles to represent 12A.

    The arr you have there is incorrect - as there is no 2 in binary.

    arr[0]=0001
    arr[1]=0010
    arr[2]=1010
    

    For c# implementation see - How can you nibble (nybble) bytes in C#?