Home > Enterprise >  How to separate a two digit hexadecimal number into its digits?
How to separate a two digit hexadecimal number into its digits?

Time:04-16

Suppose I have a hexadecimal number 4e. How to get 4 and e separately and store it in two separate variables?

CodePudding user response:

if you mean 'how can I get the upper and lower nibbles of a byte into two variables'

 char x = 0x4e;
 int low = x & 0x0f;
 int high = (x & 0xf0) >> 4;
  •  Tags:  
  • c
  • Related