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 28 or 256 different values. This makes it appropriate for storing things like a single character of text - with 256 different values we can assign a different 8-bit pattern to each letter, digit, punctuation mark, etc…

When more than eight bits are required for some data, several bytes are used. For example, typically:

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

20

Kibibyes (KiB)

1024

210

Mebibytes (MiB)

1,048,576

220

Gibibytes (GiB)

1,073,741,824

230

Tebibyte (TiB)

1,099,511,627,776

240

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 103 bytes. Using that system gives us the following units:

Name

Number of Bytes

Power of 10

Byte

1

100

Kilobytes (KB)

1000

103

Megabytes (MB)

1,000,000

106

Gigabytes (GB)

1,000,000,000

109

Terabyte (TB)

1,000,000,000,000

1012

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 256×106 or 256×220 bytes. The same source may even use the MB, GB, etc… notation to mean both base 10 and base 2 when describing different measurements. For example, if you buy a computer advertised with “16 GB” of main memory (RAM) and a “500 GB” hard drive, the 16 GB means 16×230 while the 500 GB means 500×109!

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 109 or 230 for each GB.

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.

Materials on this page adapted with permission from from:
Introduction to Computer Science using Java by Bradley Kjell (CC BY-NC 3.0)
You have attempted 1 of 3 activities on this page