I am writing a C program that has to show each operation in a hexadecimal answer but you have to show all the bytes corresponding to the data type.
for example if its an int it should show 8 bytes, if its a short 4 bytes.
It works for every other data type including char where it only shows two bytes. But short is always showing 8 bytes when I print it
char x5 = 0xa1;
short z5 = x5;
printf("\nProblem 1f: %x\n", z5);
and it prints "Problem 1f: ffffffa1"
a classmate found a solution where %hx prints the correct amount of bytes but I dont understand why this %x prints extra bytes, where are these bytes coming from?
Thanks in advance!