3.6. Bytes¶
One bit of information is so little that usually computer memory is organized into groups of eight bits. Each eight-bit group is called a byte. Because it has 8 bits, it can store
When more than eight bits are required for some data, several bytes are used. For example, typically:
An integer is represented with a group of 4 bytes (32 bits)
A decimal number is represented with a group of 8 bytes (64 bits)
A color is repented by a group of 3 bytes (24 bits)
When we are talking about much larger chunks of information, like the information that makes up an entire image or music file, we describe it in terms of Kibibytes, Mebibytes, Gibibytes or even larger quantities. These are all names for different powers of 2:
Name |
Number of Bytes |
Power of 2 |
---|---|---|
Byte |
1 |
|
Kibibyes (KiB) |
1024 |
|
Mebibytes (MiB) |
1,048,576 |
|
Gibibytes (GiB) |
1,073,741,824 |
|
Tebibyte (TiB) |
1,099,511,627,776 |
3.6.1. Powers of 2 vs 10¶
In the metric system, Kilo, Mega, Giga, etc… refer to different powers of 10. So a Kilobyte, or KB, is
Name |
Number of Bytes |
Power of 10 |
---|---|---|
Byte |
1 |
|
Kilobytes (KB) |
1000 |
|
Megabytes (MB) |
1,000,000 |
|
Gigabytes (GB) |
1,000,000,000 |
|
Terabyte (TB) |
1,000,000,000,000 |
Unfortunately, this distinction between units like KB and KiB is a relatively recent one and is not used consistently. If someone specifies one of the KiB, MiB, etc… values, you can be sure that they mean a power of 2. However, when someone specifies a value without the little i, like KB or MB they may be specifying a power of 2 or 10. “256 MB” can either mean
Fortunately, the values of the base 2 and base 10 systems are close enough that a value like “32 GB” gives you a good idea of how big the value is even if you aren’t sure how to interpret the GB. But if you desire an exact value, you need to figure out whether you should be using
Note
Traditionally, people describe processor speeds, network speeds, and hard drive space using the power of 10’s system. They describe main memory (RAM) and the size of files and data using the power of 2’s system. This gets a bit confusing when you are calculating something like how long it will take to send a “200 MB” file over a “100 MB/s” network connection - the two MB’s are different units!
Self Check
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
Introduction to Computer Science using Java by Bradley Kjell (CC BY-NC 3.0)