Please Help Me !!!

[b]
hello everyone
How I can calculate this number(-124) from binary format??
Please Please Help Me
Note : 132 on binary ( 1 0 0 0 0 1 0 0 )

https://i.postimg.cc/jSMF4vTq/Untitled.png

Question number 2, but in French hhhh =D

https://i.postimg.cc/bwrTpPX8/Untitled-29.png

I searched a lot of sites, but I couldn't find anything :'( :'( :'(
Please Please Help Me ❤️ ❤️ ❤️
[/b]
Last edited on
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+= 1;
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.
Last edited on
@jonnin

Thank you so much bro ❤️ ❤️ ❤️
but I can't understand you well Please Could you simplify more please :'(

if I give you this : 132 = 1 0 0 0 0 1 0 0
how you can get this : -124

124 in binary:
01111100
flip the bits:
10000011
add 1:
10000100
^^ this is negative 124. (on machines that use 2's complement, which is most of them)
watch this:
01111100 //124
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:
0000000001111100 //124
0000000010000100 //132
1111111110000100 //-124

Last edited on
Don't post pictures of your question when you could type it.
Don't post French questions to an English-speaking forum.

As is, you have to wait for someone who can read French to come along and tell others what the question is.
Last edited on
@jonnin

Thank you so so much sir ❤️ ❤️ ❤️
actually I didn't understand very well ... but don't worry the problem in my mind not in the simplification which you give me :'(
@mbozzi

Sir My Mother language is Arabic Not French Not English ... So let me learn Please ❤️

And I think I'm already translated the question to English :'(

Note : in my university we study informatique on french :'(
Last edited on
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 ??

ok ok now I can get this -124 from this 132 = 1 0 0 0 0 1 0 0

Thank You very very much sir ❤️

last question please ... on base (10) it means 16 bits ??

because in the question 2 on (photo) .... want me do this in base (10) !!
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
Last edited on
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)
Last edited on
Registered users can post here. Sign in or register to post.