Hello everyone, I need some help with working with hexadecimal variables in C. I don't know exactly what is going wrong, as the program runs without an error, but I need to input a 16 digit hexadecimal number into the program, and then separate the digits 2 at a time. The problem is that it successfully separates the 8 digits to the right, but then for whatever reason, the left 8 digits aren't even defined int the variable. Here is my code for reference:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(void) {
int i, j;
int m = 0;
unsigned long int hexedit;
unsigned long int hex = 0x10387cfe38383800;
printf("%lx\n", hex);
for (i = 1; i <= 8; i++) {
hexedit = ((hex >> m) &0xff); // shifts digits and separates 2 digits
printf("%lx ", hexedit);
m += 8;
}
return EXIT_SUCCESS;
}
My output is below as well:
38383800
0 38 38 38 0 38 38 38
The last 4 outputs should be the last 8 digits of the input from right to left, but instead, it's just repeating the correct 4 outputs. The outputted unedited value shows it just stops at first 8 digits.
I'm not sure if it's the format specifiers (admittedly, idk what the correct specifier would be), but this is something I haven't really seen before. Any help would be appreciated, thank you.