Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,122 questions

40,780 answers

573 users

How to extract bytes from hexadecimal value in C

1 Answer

0 votes
#include <stdio.h>
 
int main()
{
    unsigned int n = 0x99A077FF; 
     
    unsigned char a, b, c, d; 
     
    a = (n & 0xFF); 
    b = ((n >> 8) & 0xFF); 
    c = ((n >> 16) & 0xFF); 
    d = ((n >> 24) & 0xFF); 
 
    printf("a = %02X\n", a);
    printf("b = %02X\n", b);
    printf("c = %02X\n", c);
    printf("d = %02X\n", d);
}
  
/*
 
run:
 
a = FF
b = 77
c = A0
d = 99
 
*/

 





answered Jul 20, 2018 by avibootz
...