extract a byte out of an integer in C

0
int data = 0x69bd2ab7;
char byte1 = (data >> 16) & 0x000000FF;
printf("Extracted: 0x%x\n", byte1);

The above prints:

Extracted: 0xffffffbd

How do I get rid of the prepended ff's and print 0xbd?

c
bit-manipulation
asked on Stack Overflow May 1, 2018 by Kat

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0