How to print 4-byte integer byte by byte in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    unsigned int n = 1150336788;
    unsigned char* p = (unsigned char*)&n;
    
    printf("Integer hex value: 0x%08X\n", n);
    
    printf("Byte by byte: %u %u %u %u\n", *p, *(p + 1), *(p + 2), *(p + 3));
    
    return 0;
}

// 14 hex = 20 dec
// BF hex = 191 dec
// 90 hex = 144 dec
// 44 hex = 68 dec

 
 
/*
run:
 
Integer hex value: 0x4490BF14
Byte by byte: 20 191 144 68
 
*/

 



answered Jul 28, 2024 by avibootz
edited Jul 28, 2024 by avibootz

Related questions

2 answers 57 views
1 answer 73 views
1 answer 184 views
...