Linked Questions
23 questions linked to/from Why does printf not print out just one byte when printing hex?
32 votes
3 answers
28k views
printf adds extra `FFFFFF` to hex print from a char array [duplicate]
Consider the following simplified code bellow. I want to extract some binary data/stream from a file and print it to the standard output in Hexadecimal format. I got extra 3 bytes 0xFFFFFF. What's ...
8 votes
2 answers
14k views
When printing hex values using %x why is 'ffffff' printed after each value? [duplicate]
In a sample c++ code I will open a file and print each char in hexa file has only 16 chars but why ffffff will print after each heax values? char buff[256]; // buff filled with fread for(i=0;i<16;...
3 votes
3 answers
1k views
Why printf show false value of an hex number [duplicate]
Code char a; a = 0xf1; printf("%x\n", a); Output fffffff1 printf() show 4 bytes, that exactly we have one byte in a. What is the reason of this misbehavior? How can I correct it?
2 votes
2 answers
1k views
Signed Char Decimal to Hexadecimal Conversion in C programming [duplicate]
I was trying to work on something and I basically have two questions. When creating a signed char, how do you a) what is the convention of initialization and print statement used to print it in ...
2 votes
2 answers
764 views
Is there way to get the last byte of data of off a short and save it into a char [duplicate]
I'm following a tutorial to write an emulator for the Chip8. Opcodes are 2 bytes long and in HEX. They are stored in unsigned short data types (which is 2 bytes). I want to get the last byte off of ...
-1 votes
2 answers
432 views
How do format specifiers work internally? [duplicate]
Consider: int x=0xdeadbeef; char c=x; printf("%x",c); The output is ffffffef. How? Why is it NOT 000000ef?
1 vote
1 answer
675 views
Binary file Reading, add extra characters in c? [duplicate]
I try to read binary(executeable) files, butsome problem as it prints extra character(0xffffff) after every few bytes. But this code work perfectly for text file(Non-binary). The code is: int main(...
3 votes
1 answer
200 views
Hexadecimal representation of generic data type value in C [duplicate]
I was trying to write a function in C to print out the hexadecimal representation of a generic data type value. My first attempt was failed, the second succeeded, why? First attempt #include <...
0 votes
3 answers
261 views
after dereferencing a char pointer i'm getting unexpected output [duplicate]
I want to send some 8 bit data(in HEX format) out of 16 bit data from my buffer using char ptr, so for this purpose I took "Unsigned short int" array and dereferencing it using char.But in ...
0 votes
0 answers
217 views
extract a byte out of an integer in C [duplicate]
int data = 0x69bd2ab7; char byte1 = (data >> 16) & 0x000000FF; printf("Extracted: 0x%x\n", byte1); The above prints: Extracted: 0xffffffbd How do I get rid of the prepended ff's and print ...
0 votes
1 answer
101 views
Copying char array and printing hex from copied array gives error [duplicate]
I was trying a basic program to copy elements form one array to another. The source array is having more elements. While copying elements from source to destination i only copy few elements from ...
1 vote
1 answer
109 views
Bit toggling confusion in C [duplicate]
Hi I have written a program to toggle bits in char array. I found that when I am toggling the 7th bit I am getting wrong answer. Please help me. int main() { int n,c; char dummy; scanf("%...
0 votes
0 answers
39 views
The strange bytes result of dividing 0 in C programming [duplicate]
I am studying the IEEE 754 that stipulates 4 types floating-point number, formatted, unformatted, infinity and NAN. In my C program, I test what will happen if dividing 0 and print the bytes of the ...
0 votes
0 answers
21 views
Problems with the read syscall [duplicate]
I am writing a simple program that reads data from two files and performs a byte-by-byte comparison to find the first(if any) difference between the two. Here is the code I'm having trouble with: it ...
20 votes
4 answers
49k views
Format specifier for unsigned char
Say I want to print unsigned char: unsigned char x = 12; which is correct. This: printf("%d",x); or this: printf("%u",x); ? The thing is elsewhere on SO I encountered such discussion: -Even with ...