How your computer differentiates between positive and negative numbers [Math Mondays]
Also relevant to how your computer stores Decimals
To learn more about the newsletter, check our detailed About Page + FAQs
To help me understand you better, please fill out this anonymous, 2-min survey. If you liked this post, make sure you hit the heart icon in this email.
Recommend this publication to Substack over here
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^2. 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]
To know what Math Topics are most important for Computer Science, read this
I created Technology Interviews Made Simple using new techniques discovered through tutoring multiple people into top tech firms. The newsletter is designed to help you succeed, saving you from hours wasted on the Leetcode grind. I have a 100% satisfaction policy, so you can try it out at no risk to you. You can read the FAQs and find out more here. Use the button below to get 20% off for upto a whole year.
Before proceeding, if you have enjoyed this post so far, please make sure you like it (the little heart button in the email/post). I also have a special request for you.
***Special Request***
This newsletter has received a lot of love. If you haven’t already, I would really appreciate it if you could take 5 seconds to let Substack know that they should feature this publication on their pages. This will allow more people to see the newsletter.
There is a simple form in Substack that you can fill up for it. Here it is. Thank you.
https://docs.google.com/forms/d/e/1FAIpQLScs-yyToUvWUXIUuIfxz17dmZfzpNp5g7Gw7JUgzbFEhSxsvw/viewform
To get your Substack URL, follow the following steps-
Open - https://substack.com/
If you haven’t already, log in with your email.
In the top right corner, you will see your icon. Click on it. You will see the drop-down. Click on your name/profile. That will show you the link.
You will be redirected to your URL. Please put that in to the survey. Appreciate your help.
In the comments below, share what topic you want to focus on. I’d be interested in learning and will cover them. To learn more about the newsletter, check our detailed About Page + FAQs
If you liked this post, make sure you fill out this survey. It’s anonymous and will take 2 minutes of your time. It will help me understand you better, allowing for better content.
https://forms.gle/XfTXSjnC8W2wR9qT9
I see you living the dream.
Go kill all and Stay Woke,
Devansh <3
To make sure you get the most out of Math Mondays, make sure you’re checking in the rest of the days as well. Leverage all the techniques I have discovered through my successful tutoring to easily succeed in your interviews and save your time and energy by joining the premium subscribers down below. Get a discount (for a whole year) using the button below
Reach out to me on:
Instagram: https://www.instagram.com/iseethings404/
Message me on Twitter: https://twitter.com/Machine01776819
My LinkedIn: https://www.linkedin.com/in/devansh-devansh-516004168/
My content:
Read my articles: https://rb.gy/zn1aiu
My YouTube: https://rb.gy/88iwdd
Get a free stock on Robinhood. No risk to you, so not using the link is losing free money: https://join.robinhood.com/fnud75