How your computer differentiates between positive and negative numbers
How do computers store negative numbers? After all, the binary system conversion most people learn in school just covers converting whole numbers (ints from 0 upwards) into Binary/Hexadecimal bases and vice-versa.
What about floats and decimals? How can the computer store them in your system? Take a second to think before proceeding.
Did you spend time thinking and coming up with your solution?
Seriously?
You didn’t just rush through?
Don’t look without thinking. You’re only hurting yourself. I’ll give you the best information and action plans out there- but it only helps if you are willing to put in the leg work. Having Cristiano Ronaldo coach you in football will be useless if you’re not waking up at 6 AM to train.
I trust you. You have been putting in the work. I see it in the testimonials, email replies, and ideas you share with me regularly. Keep at it and we will kill all, together.
Now let’s get into this Math Monday.
Important Highlights
- Prereqs- This post assumes you have a basic understanding of the binary number system and how to convert between different number systems. As a developer, this is a non-negotiable. If you don’t know this well, reach out to me and I will make a post on this.
- How Computers Store The Sign of the numbers- We know that computers take out memory to store any Data, including numbers. One unit of this memory is called a bit and can store 2 values (0 or 1). We use one bit to store the sign of the number and the rest to store the values. Say we took out 8 bits of memory for our number. Then, you would take one bit for the sign and the other 7 for storing the actual value. Fun math question- what is the range of values you can store using 7 bits? Assume you only need to store ints for now.
- Getting into storing Decimals- We can use a similar approach to store decimals. How? Think back to your early education days and learning about scientific notation. You know you can write 123 as 1.23* 10². Similar logic. We can represent our binary numbers with similar notation (using base 2 instead of 10). After this, all we need to do is store the exponent and the base value, and BOOM- floating point value stored. I’m linking a video below to show you the process, step by step.
- Big Picture Takeaway- Notice how we solved this system by applying the basic conversion and storage protocols multiple times in slightly different contexts. Many problems in software engineering, math, and computer science are solved this way. This is called reducing your problem. In non-fancy terms- you take a complex problem you’re trying to solve and try to carve it up into simpler problems you have already solved. Comment about places you’ve seen this.
- Quantum computing- Some of you, especially my younger audience, will end up working on Quantum Computing. Qubits have some differences from the traditional bits, which make a huge difference in performance. Do you think this way of storing will be efficient in the quantum setting? Why or why not?
If you don’t get the last question immediately, don’t worry. I’ll be doing a Math Monday on Quantum Computing and superpositions soon. Keep your eyes peeled out for that. I just thought I’d get your mind thinking in that direction.
To those of you interested in the mechanics of storing numbers in binary scientific format, watch the video below. It’s an excellent overview of the process. Make sure you show the creator some love.
To learn Math more effectively, check out my post- Math is a Language. This is how you should learn it. [Math Mondays]
That is it for this piece. I appreciate your time. As always, if you’re interested in working with me or checking out my other work, my links will be at the end of this email/post. If you like my writing, I would really appreciate an anonymous testimonial. You can drop it here. And if you found value in this write-up, I would appreciate you sharing it with more people. It is word-of-mouth referrals like yours that help me grow.
Save the time, energy, and money you would burn by going through all those videos, courses, products, and ‘coaches’ and easily find all your needs met in one place at ‘Tech Made Simple’! Stay ahead of the curve in AI, software engineering, and the tech industry with expert insights, tips, and resources. 20% off for new subscribers by clicking this link. Subscribe now and simplify your tech journey!
Using this discount will drop the prices-
800 INR (10 USD) → 640 INR (8 USD) per Month
8000 INR (100 USD) → 6400INR (80 USD) per year (533 INR /month)
Reach out to me
Use the links below to check out my other content, learn more about tutoring, reach out to me about projects, or just to say hi.
Small Snippets about Tech, AI and Machine Learning over here
AI Newsletter- https://artificialintelligencemadesimple.substack.com/
My grandma’s favorite Tech Newsletter- https://codinginterviewsmadesimple.substack.com/
Check out my other articles on Medium. : https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Reach out to me on LinkedIn. Let’s connect: https://rb.gy/m5ok2y
My Instagram: https://rb.gy/gmvuy9
My Twitter: https://twitter.com/Machine01776819