the negative in binary is usually denoted via 2s complement. This is usually stated flip the bits and add 1.
I think this may do it:
unsigned char c = 124;
c = ~c; //binary, not boolean, not operator
c is now -124:
char c2 = c;
cout << (int)c2;
printing binary is a pain, you have to write your own routine for that.
the easy way is to make a 16 entry lookup table of hex digits, print the number to a string as hex, look up the binary, and assemble it that way.
your post looks a lot like spam. You may want to ease up on the hearts and fluff and unnecessary links so people do not mistake your posts.
124 in binary:
flip the bits:
^^ this is negative 124. (on machines that use 2's complement, which is most of them)
10000100 //132 lets add them:
(1)00000000 //but the extra 1 is overflow, its outside the bit pattern range we use, so its zero... -124 + 124 == 0, then...
and it is also 132 in unsigned char.
but remember that a SIGNED character only goes from 0 to 127. 132 is out of bounds; those bit patterns are reserved for the negative numbers.
so 132 IS -124, depending on how YOU the programmer tell the machine to understand that bit pattern.
if you had 16 bit numbers instead of 8, you can have both 132 and -124 exist, because the range is increased. there are a lot of leading zeros (positives) or leading 1s (negatives) on the values that I do not care to type out. But these extra bits make them unique, allowing both to exist in the 16 bit and greater bit pattern world. Lets take a look:
in 16 bit you get:
I don't know how else to say it.
unsiged vs signed, 132 and -124 have the same bits in an 8 bit world; they overlap but that is ok because YOU know if it is signed or not in your program. They cannot exist together in signed 8 bit; signed 8 bit does not have enough bits to represent both.
if I understand well ... we need almost 16 bits to represent -124 and 132 on binary that is right ??
YES. Integer types in c++ (really, on computers) are in powers of 2, so because there is no 10 bit integer type, you need 16 or greater.
base 10 has NOTHING to do with bits. base 10 is what we humans use most, eg the number one hundred is 100 .. that is base 10. Computer work in bits because electric circuits have power to them, or not, this is true or false, 1 or 0, however you think of it, it makes using binary important at the hardware level. Programmers sometimes use the bits of an integer to do clever things (like using a 8 bit integer as if it were 8 booleans), because it is handy to do so. An example of base 10 not being tied to bits: a megabyte is 2 to the 20th power, not one million bytes. Its VERY close to 1 million, but not exactly. This trips up people the first time they see it; many novice computer users do not know it even in 2020.
I have no idea what the question wants in base 10.
-124 is -124 in base 10.
132 is 132 in base 10.
to change a number to negative in base 10, you apply a - sign to it.
I guess you can do it formally in math somehow, like 0 - number
I can see that there is some confusion on "2's Complement". Let's take the 8-bit character example. "Unsigned" characters count for 0 to 255. "Signed" characters ("char") count from -128 to +127. The first bit (left-most) is the sign---"1" for negative, and "0" for positive. The other 7 bits indicate a number between 0 and 127. If the sign bit is set ("1") the numbers count forward from -128.
In this example: 10000100
1 = "Negative"
0000100 = 4
So, the result is: -128+4 = -124
In the case of 16-bit, the negative numbers would count forward from -32768.... -(2^15)