c++ - Signed vs Unsigned comparison -
#include <iostream> int main() { signed int = 5; unsigned char b = -5; unsigned int c = > b; std::cout << c << std::endl; }
this code prints 0
.
can please explain happening here? guessing compiler converts a
, b
same type(unsigend int
maybe) , compares them.
let's see how computer stores value b:
5
00000101
, -5
11111011
, so, when convert unsigned char
, became positive number value 11111011
in binary, larger 00000101
.
so, that's why a = 00000101
smaller b
(0 means false).
Comments
Post a Comment