+ 3

c++ char truncation

Can someone explain why the variable has been truncated to 232? A char is 8 bits, so why not to 255 https://code.sololearn.com/cJDB8jQKcjQ7/?ref=app

17th Sep 2018, 9:19 PM
. �
.                                                � - avatar
1 Antwort
+ 4
It's modulo. 1256 % 256 == 232 Basically everything that doesn't fit into 8 bits gets cut off. 1256 is 10011101000 in binary and the leftmost 3 bits are too much. What's left over is 232. __ EDIT: Another way to say it is that you start at 0 and keep counting up. Once you hit 255 you then reset to 0 again. If you've counted up 1256 times you end up at 233.
17th Sep 2018, 9:36 PM
Schindlabua
Schindlabua - avatar