strange padding in printf?

so i got this code.
1
2
3
4
5
6
7
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char* argv[]){
   char H = 0xAB;
   printf("%X\n",H);
}


and i expect it to print AB but instead i get FFFFFFAB
if i just say 0xA in the code i get A as output, but if i use AB why does it get padded?
char is 8 bit signed. So everything 0x80+ (128+) which has the highest bit set is interpreted as a negative value. printf converts 'H' to int (32 bit). 0xab = -85 -> int 0xFFFFFFAB.

0xA < 0x80 hence not negative.
Topic archived. No new replies allowed.