printing - C print hex bytes -


i have code in c program hex data want iterate over, example print out each of hex bytes:

char input[] = "\x31\xd2\xb2\x30"; (int = 0; < strlen(input); i++) {     printf("%02x\n", input[i]); } 

however, output not expect, example above prints:

31 ffffffd2 ffffffb2 30 

i tried cast output (unsigned int), receive same output.

can point out issue simple script?

the arguments passed printf sign extended unless cast them unsigned type this:

printf("%02x\n", (unsigned char)input[i]); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -