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

StackOverflow https://stackoverflow.com/questions/19766064

  •  03-07-2022
  •  | 
  •  

Domanda

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?

È stato utile?

Soluzione

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#?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top