Home DSA Easily Calculate Memory From Bytes to KB, MB, GB, TB

Easily Calculate Memory From Bytes to KB, MB, GB, TB

Published: Last Updated on 0 comment

Hello Devs! Welcome to the Instant Tea section from CodersTea.in. Here I will directly jump to the solution i.e. “Show me the Code, Damn it”. If you need to know the code in more detail, then let me know in the comments. I will add the link to my (old or the one I will be writing) or other resources for you.

Let us quickly jump to the solution for the problem you asked 🤔

Easily Calculate Memory From Bytes to KB, MB, GB, TB

Here is the list with numbers of bytes for each size. With this, you can quickly identify which size metric to show instead of saying a number of bytes. Very helpful for your next System Design Interview.

1 Byte = 8 bit. For simplicity, I am using 1000 as the base instead of 1024 for KB and further calculations. You can mention this to the interviewer to make them aware.

SizeAbbr.Number of
Bytes (words)
Number
of Zeroes
Number of Bytes
KiloBytesKBThousands – K31,000
MegaBytesMBMillions – M61,000,000
GigaBytesGBBillions – B91,000,000,000
TeraBytesTBTrillions – T121,000,000,000,000
PetaBytesPBQuadrillion – Q151,000,000,000,000,000
ExaByteEBQuintillion – 🤷‍♂️181,000,000,000,000,000,000
ZettaByteZBSextillion – 🤷‍♂️211,000,000,000,000,000,000,000
YottaByteYBSeptillion – 🤷‍♂️241,000,000,000,000,000,000,000,000
Bytes Calculations (best view on Desktop)

How to Use This to Calculate Size in System Design Interview

Example with Database Record

Let’s say I am in a system design interview. I want to store N numbers of records. N can be any number from thousands to Quadrillion. Each record is approximately 1000 Bytes.

Here is how I can solve this for various values of N. Always remember that in System Design Interview assumption is in your hand (most of the time), so choose a number that would be easier to calculate. like 100 Million, 50 Million, 1 Billion etc. Don’t choose any arbitrary number like 333 million, or 43.8 thousand.

N = 100 Million. Records are 1000 Bytes each. I will do, 100 Million (from records) * 1000 (record size) = 100 * 1 Million * 1 Thousand. The multiplication result would be the addition of zeroes 😉. That would be 2 zeroes + 6 zeroes + 3 zeroes (from 100, 1M, and 1K respectively) = 11 zeroes = 100 Billion. From the list, it would become 100 GB.

For N = 40 Million. Number of zeroes would be 40 * 1 M * 1 K = 1 Zero + 6 Zeroes + 3 Zeroes = 10 Zeroes = 10 Billion. Taking 4 of 40 would be 4 * 10 Billion = 40 Billion = 40 GB.

Example with File

Another example is where I have M number of audio files with an average size of 7MB. Again, M can be any number, 80 Million, 1 Billion, etc.

M = 70 Million. 7 MB * 70 Million. 6 Zeroes from 7 MB and 7 Zeroes from 70 MB. It would become 6 + 7 = 13 Zeroes = 10 Trillion = 10TB. And both are 7 so 7 * 7 = 49 so it would be 10 * 49 = 490 TB. or 0.49 PT, rounding off to 0.5 PT

You can quickly go through the list before your system design interview for reference.

On a totally unrelated note 🤓, read my post on A Quick Glance at Sorting Algorithms Code in Java with Code on GitHub.

It’s Done, But one more thing You can Do 🫵

And yes, that’s your solution there. I hope this will work for you. Let me know in the comments if you have any other solution. See all other Instant Tea posts here. Before going, do connect with us on social media.  It’s @coderstea on TwitterLinkedinFacebookInstagram, and YouTube.

Also, please subscribe to our newsletter to know about the latest updates from CodersTea.

See you in the next post.

HAKUNA MATATA!!!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Ads
Ads
Ads

@2023 All Right Reserved. Designed and Developed by CodersTea

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More