Please explain what the output is showing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please explain what the output is showing

v5 https://code.sololearn.com/cfExmc7WtXHj/?ref=app

13th Oct 2023, 4:21 AM
Vaibhav Chauhan
Vaibhav Chauhan - avatar
1 Answer
+ 5
Vaibhav Chauhan the output you see is the console representation of an invalid ASCII character value 249. To explain why it is 249, I need to describe how negative integers are stored. In case you already are aware how it works, I will only give it briefly. For more detail, you may search it out. Negative integers are stored in Two's Complement form. Two's Complement of a number is made by performing bitwise Not and adding 1. The value in your variable v2 is -7. To print the character it uses the unsigned value. As an unsigned value it would have the same bit pattern as 249. Here is the Two's Complement process for -7: 00000111 (7) 11111000 (~7) 11111001 (~7)+1 = -7 128+64+32+16+8+1 = 249 [more easily: 256 - 7 = 249] Valid ASCII characters are only in the range 0 - 127. So 249 is in the Extended ASCII set, which has non-standard character representation, therefore it prints a special question mark character.
13th Oct 2023, 4:56 AM
Brian
Brian - avatar