how do binary numbers have a minus sign?? (not 1 or 0)

preview_player
Показать описание
In algebra, doing math with negative numbers is simple. By putting a negative sign in front of a number, the number is known to have negative value. But how does this work with binary numbers?

Binary numbers cannot be "negative". By saying that a number is either unsigned or signed, the most significant bit of the number will denote if the number is positive or negative, allowing us to do math just like we would with any other number.

🏫 COURSES 🏫

🔥 SOCIALS 🔥

Рекомендации по теме
Комментарии
Автор

To be exact, unsigneds aren't strictly positive: zero is fine too. 😉
All in all, it's just an interpretation (two's complement being example of handy ones). IEEE 754 reals have sign separated from mantissa/significand, same for IBM packed BCDs. This allows the range to be symmetric, and two zeros sometimes.

-wx--
Автор

Amazing video! Now... what about floats?

marcosg
Автор

You covered these subtleties well. I remember finding them tricky when I first learned about them.

For the next level, I’d say cover the two’s compliment. That’s a clever, unusual, effective idea I bet this audience would appreciate.

Mutual_Information
Автор

Ben Eater has a really good video on two's complement as part of his 8-bit breadboard computer series. If you want a more in-depth explanation of why flipping the bits and adding 1 somehow magically makes a binary number negative he does a really good job at explaining it.

nightfox
Автор

Caveat: There _is_ a negative sign in binary. Binary is just a positional system like decimal or any other. There isn't a negative sign _in computer memory_ ;)

xGOKOPx
Автор

This video format is amazing! It would be cool to see this for other low level concepts and stuff like file systems, shells etc

jesperkha
Автор

This is so cool. I’m self teaching and was wondering the difference between signed and unsigned ints just a few days ago. Found the wiki and understood well enough, but now I understand it a even better and at a bitwise level.

Thanks man

GlutesEnjoyer
Автор

If you wanna get really technical (or mathematical for that matter), you could also say that -x in binary is the 2-adic additive inverse of x, truncated at the bit-size

TheyCallMeHacked
Автор

As a CS student I found this interesting and informative. I am familiar with the concepts of Int's and Floats, signed vs unsigned. I have yet to get into binary mathematics yet, so this was a fun insight, thanks!

Wandering_Horse
Автор

a tiny bit of positive feedback and a gotcha which threw me until I read it (good lesson in programming i guess, don't assume) is that at 2:35 you show a demo of the assigning an UINT and an INT, with the UINT being the "top" value declared... ok cool... but then the output was -1 🤔 but I thought UINT's underflow.... then I looked at the printf and realise your output order is swapped around from your variable declaration order (which I was using as a reference to which value was which) Thought I'd point it out in case it throws anyone else.

Great content as always! still binge watching all your stuff!!

TornTech
Автор

When explaining this topic, I ussually show an example with 10's complement as well. Actually, I only show the 9s complement, and put a 1 in the one's place carry. A NEG does add the 1, but a SUB or CMP just takes the 1's complement (just inversion) instead of 2's, and uses a full adder circuit with a carry set for the least significant bit, which allows the 2's complement conversion and the subtraction operation to share the carry propagation.

jaysistar
Автор

In mathematics a negative number -x of a number x is so that x + -x = 0.

cherubinth
Автор

0:46 The oversimplification here is misleading. There are *2 kinds* of "binary" in computing, "raw"/"packed" and "expanded".

Raw-bin are just the hardware bits, that's "strictly binary" meaning there are only 2 symbols available in the alphabet of that Turing machine. These can be represented in many ways: "A B", "B A", "0 1", "1 0", "Off On", "Black White", "Down Up", etc...

Expanded-bin is an abstraction of the implementation details. Expanded can have many formats and encodings, the most common is the ASCII Arabic digits "0" and "1", whose raw binary representation requires 8bits per digit (1/8 efficiency compared to raw). Another encoding for binary is "expanded hexadecimal" (which is never used raw, because no modern computer has "half bytes"/"nibbles") which (in ASCII) occupies 8b for each nibble (1/2 efficiency, better)

The decimal numeral system we use is expanded, so expanded-bin DOES allow a negative sign

Rudxain
Автор

Not one of my "introductory" textbooks on C explained this, they always just assumed you knew binary number arithmetic

electrictrojan
Автор

2:10 what? didn’t understood that addition

gianclgar
Автор

So, mixing signed and unsigned numbers is generally a bad idea.

donaldmickunas
Автор

I am a foreign speaker of German, and I learned the old system. I find the writing reforms from the 1990s to be deeply alienating.

XalphYT
Автор

there is also sign-magnitude representation where the first bit really acts like a negative sign. But there is the problem that we have 2 zeros, also adding doesnt work at all. An alternative is to flip the ordering of the negative numbers (we count down instead of up when we go past the maximum signed number): 1's complement, where a negative is just the number with all the bits flipped. We still have 2 zeros but adding mostly works actually we are always one off and to fix this last issue we just add 1 to the negative numbers so we get 2's complement. (we could also add 1 to the positive numbers, since its all just a matter of representation)

wChris_
Автор

This is why unsigned numbers have a bigger range - it uses the sign bit to represent the positive number.

test
Автор

"If it's unsigned, always positive. If it's signed, if the most significant bit is 0 - positive, 1 - negative." is not a lot of information

Yehor-vy
visit shbcf.ru