Views : 74,327
Genre: Science & Technology
Date of upload: Jan 12, 2023 ^^
Rating : 4.958 (52/4,958 LTDR)
RYD date created : 2024-05-14T20:05:46.224092Z
See in json
Top Comments of this video!! :3
3:20 2.1 billion is for a SIGNED int. unsigned int goes to 4.2 billion
53 |
Just a heads up on a slight inaccuracy: you described the “signed magnitude” representation of signed integers, but modern hardware doesn’t use this. It uses the “two’s compliment” representation. This representation allows for integer addition and subtraction to run on the same hardware, and makes it so taking the negative of a number is as simple as flipping all of the bits of the number and adding 1.
Either way, nice refresher on my CS101 course from a few years ago!
186 |
5:58 correction, we don't use a sign bit to represent a number which would result in the existence of 0 and -0 (negative 0), for example 0000 and 1000 in int4, instead we use 2's complement numbers, where essentially we take the leftmost bit and flip it's sign, for example xyzw int4 would equal to 2^0*w + 2^1*z + 2^2*y - 2^3*x (attention to the minus in the equation)
100 |
This video on binary numbers and buffer overflow/underflow is an absolute gem! The explanations were clear and easy to follow, and the real-world applications highlighted throughout made the material relatable and understandable. It's a great resource for anyone looking to deepen their knowledge on the subject matter. Thanks for sharing.
10 |
Dude every video you make has something cool and nerdy in it I love it. Thanks for contributing man.
I was installing Linux the other day and wound up on your vids.
I was learning how to a cook a dessert and wound up on your vids.
I was learning about security vulnerabilities and wound up on your vids.
You're like a a modern lightweight tech-Da Vinci. That's intended to be a compliment. :)
112 |
It's not true, that bigger integers are necessarily slower.
Often math on bigger integers is even faster than on smaller ones. The most efficient number is often the one corresponding to the architecture. If you're on a 32 bit system, 32 bit integers are often the fastest, if you're on a 64 bit system, 64 bit integers are often the fastest.
But what's more important than that is cache size and alignment. Using bigger numbers might be bad for the cache, using different sizes of integers depending on the use case might be bad for the alignment. The latter is normally optimized by the compiler, so there is empty space between integers, so you don't have the smaller size for using smaller integer sizes for some values, while still using having the overhead of doing math with smaller integer sizes.
40 |
3:24 Should it be *signed*, rather than unsigned? An unsigned 32-bit integer should be able to go up to 4.2bill instead of only 2.1bill, if I'm not mistaken.
19 |
You should probably make a distinction between sign-magnitude notation and two's compliment. The image at 5:57 shows sign-magnitude notation, where the difference between a 7 and -7, for example, is just the left-most bit (so 7 = 0111 and -7 = 1111).
Floating point numbers work that way, but signed integers use two's compliment, like you show at 6:54. The big difference being that the negative numbers run the other way, so 1111 is -1 instead of -7.
The advantage of two's compliment is that you can simultaneously (a) interpret positive numbers the same as if they were unsigned (so 0111 = 7 in both the u4 chart at 1:05 and the i4 chart at 6:54) and (b) don't have to treat counting down past 0 as a special case (if we try to subtract 1 from 0000, the integer underflows, and we get 1111, which, in two's complement, is -1).
4 |
Thank you for teaching beginners how to think about numbers. I'm glad you're learning rust and getting into this!
Just one note about why programmers don't use large numbers. It's not just for performance. Actually performance is the least of our worries. It's basically because it's pointless and can even introduce a security threat.
First reality a new learner settles with is that math in programming isn't like math in real life. You'll never be able to have all the freedom you have when you do math on paper. Computers have limited memory, no matter how big they are.
After having settled with that, let's start building things.
When you build a program you build a "model" of something. Most of the time you don't need big numbers. Like when you push elements to a vector. That vector will never have a size larger than the max size of a 64 bit integer, because your memory will never be able to handle that even if you're using a super computer... why would you want to hold it in a 256 integer or 1000000 bit integer then? There's no point. Given that we settled that programming math is not like math on paper, you just ask yourself, what's the worst case scenario for a vector size? And you choose based on that.
Finally, security is an important consideration. Think of your program as a huge state machine. The more states your program can be in, the more security tests you need. Understanding the full, complete and provably correct behavior of a function that uses 8 bit integers is much easier than one that uses 128 bit integers. It's much easier to make formal proofs that will grant you security guarantees. After all, programming is not about monkey typing code, believe it or not anyone can do that, it's about delivering software that does exactly what we expect it to do, which turned out to be a difficult problem. Smaller integers can make this task much easier when used wisely.
15 |
@zander07
1 year ago
I have great respect for people that take any concept, simple or complex, and explain them in a way such that anyone can learn them
437 |