SY110: Numeral Systems in Computing


Numeral Systems in Computing

Learning Outcomes

After completing these activities you should be able to:


Cyberspace is a name for this global information system consisting of many familiar pieces — like websites, distributed video games, email — and many less familiar pieces as well, that work behind the scenes. Recall that we used the Department of Defense Joint Publication 3-12 on Joint Cyberspace Operations (JP 3-12) for defining cyberspace as

"a global domain within the information environment consisting of the interdependent networks of information technology infrastructures and resident data, including the Internet, telecommunications networks, computer systems, and embedded processors and controllers."

Computer Architecture Components - Hardware
Computer Architecture - Hardware. A system's motherboard provides the bus, or
circuits that interconnect hardware components together to pass data through
electronic signals.

The fundamental aspect of all of these interconnected systems process, store, and access digital data. As electric current passes through the system bus and between hardware components, its signal and timing serve as the foundation of binary representation as 1's and 0's. Depending on your major, courses like Electrical Engineering or Computer Engineering will get deep into electronic signaling and how the amount of voltage is controlled and processed to support computer architectures. Fortunately, we will only be discussing basic mathematical principles of what those signals represent and how computers process data at a conceptual level.

Numeral Systems

The most common numeral system on the planet is the base 10 (N10) system, where each value increments by one and each additional number represents 10n. Two Thousand Forty Eight is represented as (2 * (103)) + (0 * (102)) + (4 * (101)) + (8 * (100)). Notice that the least significant (e.g., smallest) value is always on the right. That rule will continue to be applied to all of the numeric systems used in this course.

Another great example of a base 10 system is roman numerals, where I represent 1, V=5 or ½(101), X=10, L=50, D=500, M=1000, and so forth. We're used to working with base 10, but this class will introduce you to two of the most common numeric systems used across computing, base 2 and base 16.

Binary Systems

Binary values represent two states, 1 and 0, on and off. Each value represents a binary digit or bit (b), which is a combination of the two words. Using the base 2 (N2) system, each position increments exponentially, as is the case with base 10 systems, but requires more positions. In converting the previous decimal value of Two Thousand Forty Eight to binary, it is written as 100000000000. Let's break it down:

  MSB                     LSB
  1 0 0 0 0 0 0 0 0 0 0 0
N2   211 210 29 28 27 26 25 24 23 22 21 20
N10   2048 1024 512 256 128 64 32 16 8 4 2 1
If you only add the N10 value that is on, represented by the 1 in the top row, the resulting value is 2048.

Let's compare the decimal number One Hundred Twenty Three using base 10 and base 2 numeric systems:

  1 2 3
  102 101 100
N10   100 10 1
SUM   100 + 20 + 3 = 123
  MSB             LSB
  0 1 1 1 1 0 1 1
N2   27 26 25 24 23 22 21 20
N10   128 64 32 16 8 4 2 1
SUM   0 + 64 + 32 + 16 + 8 + 0 + 2 + 1 = 123
When calculating base 2 binary values, it's required to be converted to base 10 and summated. The Most Significant Bit (MSB) is on the left and the Least Significant Bit (LSB) is on the right, indicated by the highest value and lowest values, respectively. The MSB positions to the left do not change the value of a number when zeroes are placed ahead, regardless of the number of zeroes placed. This applies to all numeric systems used in computing. In other words, the N10 value of 000,123 is the same as One Hundred Twenty Three. This also applies to binary values as 111 binary is equivalent to 7 decimal and so is 00111 binary.

The N2 value of 01111011, a string of eight-bit values, is called a byte (B). This is organized not only for the ability for humans to process data but the amount of chunks hardware components can process at a time. Realize that processing power consumes instruction sets using virtual memory sizes. The Apollo Lunar mission was equipped with a 16-bit processor that was part of the Apollo Guidance Computer (AGC) installed in the Apollo command module (CM) and Apollo Lunar Module (LM). Almost all computers and mobile devices manufactured today come with 64-bit processors as well as the 64-bit OSs that can support those instruction sets. That's why 32-bit OSs are backwards compatible, in addition to 32-bit software applications that can run on 64-bit processors.

Recall from algebra that multiplication is a form of addition and division is a form of subtraction. The latter applies when converting base 10 to base 2 but we'll elaborate on the two different techniques available for use. The first technique in binary conversion is subtracting the decimal value from the binary value, starting with the MSB and working down to zero.

Solve for the binary value of decimal 123 using the subtraction method:

  1. The highest value 123 does not exceed in base 2 is 26
  2. Subtract 26, or 64, from 123 and the remainder is 59
  3. Set the binary value of 26 to 1
  4. Repeat the process through to the LSB: Does 32 go into 59? Yes.
  5. 59-32 = 27, set 25 to 1
  6. 16 goes into 27; 27-16 = 11, set 24 to 1
  7. 8 goes into 11; 11-8 = 3, set 23 to 1
  8. 4 does not go into 3, therefore 22 to 0
  9. 2 goes into 3; 3-2 = 1, set 21 to 1
  10. Finally, 1 goes into 1; 1-1 = 0, set 20 to 1

  MSB             LSB
N2   27 26 25 24 23 22 21 20
N10   128 64 32 16 8 4 2 1
Solve   123 123-64 59-32 27-16 11-8 3 3-2 1-1
Remainder   123 59 27 11 3 3 1 0  
Binary   0 1 1 1 1 0 1 1


Solve for the binary value of decimal 123 using the division method:
  1. Base 2 (N2) remainders (R) will only be 1 or 0 and continue to divide by 2 (divisor) until the quotient is 0. Because we are starting with the dividend as the largest value, the R will begin on the right with the LSB.
  2. 123 ÷ 2 = 61 R1
  3. 61 ÷ 2 = 30 R1
  4. 30 ÷ 2 = 15 R0
  5. 15 ÷ 2 = 7 R1
  6. 7 ÷ 2 = 3 R1
  7. 3 ÷ 2 = 1 R1
  8. 1 ÷ 2 = 0 R1
  9. Quotient is now set to 0 and copy R values as binary, with MSB starting from the bottom = 1111011

  MSB             LSB
Dividend   0 1 3 7 15 30 61 123
Solve   0 1÷2 3÷2 7÷2 15÷2 30÷2 61÷2 123÷2
Quotient   0 0 1 3 7 15 30 61
Remainder   0 1 1 1 1 0 1 1
Check your work:
  MSB             LSB
Binary   0 1 1 1 1 0 1 1
N2   27 26 25 24 23 22 21 20
N10   128 64 32 16 8 4 2 1
SUM   0 + 64 + 32 + 16 + 8 + 0 + 2 + 1 = 123
Long Divison Method
Long division method in converting decimal to binary values.
Be aware of MSB/LSB location when converting to binary.
For those that prefer the long division method, the process is the same but can be visually organized in a manner that's more intuitive. Working from the bottom-up, work through the R-values and be aware that the MSB begins at the top once your dividend reaches 0. Additionally, there are only seven binary values in the example problem. If you want to have a full byte-value, add as many zeros as necessary towards the MSB until you fill the byte.

Note: Calculators will not be permitted throughout this course. It is critical for you to understand these concepts and conduct all mathematical conversions manually.

Knowledge Check: Convert the decimal value of Two Hundred Forty Six to binary.






Scaling and Prefixes

A computer is typically capable of storing and processing an immense amount of data. In order to scale, just like we do with base 10 values, prefixes are used to represent large numbers. Below are charts representing both base 10 and base 2 values used in computing. When referring to storage, data is typically referred to in bytes (B), where 20 Gigabytes (GB) is equivalent to 20,000,000,000 bytes; however, note that the International Electrotechnical Commission (IEC) standardized prefix for base 2 would be identified as 20 Gibibytes (GiB) with an accurate decimal value of 21,474,836,480 bytes. That's a difference of 1,474,836,480 bytes when comparing 20GB to 20GiB.

Measuring Data Storage and Data Transmissions
Have you ever noticed how cell phone plans and Internet Service Providers (ISPs) market data rates? Take a look at any of the popular cellular service providers, like Verizon and AT&T, or ISPs, like Xfinity and Cox, and see how data rates are measured. Are they in bits or bytes? The data allowance in the plan is likely measured in GB, whereas the data rate will be measured in Mbps - at least for 4G!

Max wireless cellular speeds between generations.
Image courtesy of CTIA.org.
Prefix Symbol Base 10 Number of Bytes (Decimal)
kilo K 103 1,000
mega M 106 1,000,000
giga G 109 1,000,000,000
tera T 1012 1,000,000,000,000
peta P 1015 1,000,000,000,000,000
exa E 1018 1,000,000,000,000,000,000
zetta Z 1021 1,000,000,000,000,000,000,000
Prefix Symbol Base 2 Number of Bytes (Decimal)
kibi Ki 210 1,024
mebi Mi 220 1,048,576
gibi Gi 230 1,073,741,824
tebi Ti 240 1,099,511,627,776
pebi Pi 250 1,125,899,906,842,624
exbi Ei 260 1,152,921,504,606,846,976
zebi Zi 270 1,180,591,620,717,411,303,424
Knowledge Check: How long would it take to download a 4 MiB image with a 1.5 Mbps connection?


Hexadecimal Systems

Bytes are a foundational principle in computing but it can be cumbersome to write out all eight bits of a byte. To simplify the amount of data that can be viewable by humans, each byte is displayed as two hexadecimal digits, or nibbles (yes, it's a play on words from byte). Hexadecimal is base 16 (N16) number system. The important point is that it gives us a concise representation for bytes since each hex digit represents a 4-bit pattern. Two hex-digits represent an 8-bit pattern, or one byte. But what happens beyond decimal values of 0-9? Just like license plates, letters allow combinations of numeric representations beyond ten digits with 10=a, 11=b, 12=c, and so on.

The following table gives the mapping between the hex, 4-bit nibbles, and decimal values:

hex digit  0 1 2 3 4 5 6 7 8 9 a b c d e f
4-bit nibble  0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
decimal  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Solve for the hex value of decimal 123:
  1. If you don't know the binary value of decimal 123 then do the conversion from decimal to binary but this should have been previously completed from the readings above.
  2. Split the byte values to nibbles (4-bits) and convert decimal values to hexadecimal.
Bin   0 1 1 1 : 1 0 1 1
N2   23 22 21 20 : 23 22 21 20
SUM   0 + 4 + 2 + 1 : 8 + 0 + 2 + 1
Dec   7 : 11
Hex   7 : B
N16   161   160
With many numeric systems and conversions between different base numbers, how can someone tell what-is-what if there's no unit of measure indicated? There should always be a unit of measure indicated, to include any answers provided. It doesn't help if a question is written in a way that is not effective for someone to understand, such as "convert 110 to hex." Is 110 decimal or binary, assuming that 110 isn't already hex? But how would someone tell between 110 bin, dec, and hex? Two methods to indicate hex values have the symbols 0x or # preceding it. 0x110 and #FF0000 are both hex values, the first representing a decimal value of 272 and the second representing the color red in a color palette.

When converting N2 to N16, always begin with nibbles from the LSB. This is because leading zeros that would typically complete a full byte may not exist. Earlier discussions stated that 111 binary is equivalent to 7 decimal and so was 00111 binary. Let's use a larger value to convert for hex, such as 10100 whose decimal value is 20.

Based on the earlier statement in regards to leading zeros,
  if
    20 (dec) = 020 (dec)
  and
    20 (dec) = 10100 (bin),
  then
    10100 = 010100 = 00010100 (leading zeros).

Converting 10100 to hex = 0x14 when starting with LSB.

What happens if 010100 is converted to hex from the MSB? Then 010100 or 0101 0000 (trailing zeros) would be 0x50 but 0x5020 (dec)! 0x50 = 80 (dec) = 1010000 (bin). Never start converting hex or nibbles from the MSB!

When separating bin values into nibbles, it becomes much easier to read.

In restating the previous conversions with nibble separation,
  if
    20 (dec) = 020 (dec)
  and
    20 (dec) = 1 0100 (bin),
  then
    1 0100 = 01 0100 = 0001 0100.

Similarly with dec values, we separate every N10 exponent multiple of 3 with commas to make it easier to read. Now you can see that you must begin with the LSB to ensure that the proper nibble values are aligned!

Knowledge Check: Convert the decimal value of Two Hundred Forty Six to hex.




ASCII Encoding and Text

Encoding is converting data from one system of communication into another. There are other encoding schemes beyond ASCII; for example: base64, Unicode, UTF-8.

Other than numbers, the most fundamental form of data is plaintext. The method for representing text digitally (i.e. as bits and bytes) depends on the alphabet of languages. In cyberspace, English uses the American Standard Code for Information Interchange (ASCII) based on standardized telegraph code from the early 1960's. Each ASCII character is represented using one byte (i.e. one number in the range 0-255, although in reality we only use 0-127), where the characters allowed and the byte values (i.e. numbers) they correspond to are given by the ASCII Table.

So, for example, the ACII letter a has a decimal value of 97 which is byte 0110 0001 (spaced for readability). ASCII values 32-126 are the printable characters and any sequence of bytes consisting solely of them is considered to be plaintext. We might allow the additional values 9 ← tab, 10 ← newline, 13 ← carriage return, which provide limited formatting. The standard QWERTY keyboards have a 104-key configuration but, for all of the gamers and coders, there can be 115-key layouts to customize shortcuts and add key sequences.

String to ASCII Demo
Input a string and press enter
You can actually enter ASCII values that are represented in hex into the address bar in any web browser. The hexadecimal notation requires a % before the hex value. For example, the ASCII Character a has a hex value of 61, so a a can be written in the address bar as %61. Thus, entering usn%61.edu in your browser's address bar gets you to usna.edu! Certain browsers may no longer permit these actions as there are negative security implications.

A sequence of characters is called a string, and what we've just seen is that ASCII gives us a way to encode strings as sequences of bits (or, if you prefer, bytes).

Knowledge Check: Convert the byte-string 101001101011001001100010011000100110000 to hex and then to ASCII.



Supplemental Media:

How to Convert Binary to Decimal


Key Points:

  1. Each binary value represents a binary digit (bit) as a 1 or 0, on or off
  2. Byte is base 2 (N2), decimal is base 10 N10, and hexadecimal is N16 numeral systems
  3. The MSB is always towards the left and the LSB is always towards the right for binary string value
  4. A string of eight-bit values is called a byte
  5. The one technique in binary conversion is subtracting the decimal value from the binary value, starting with the MSB and working down to zero.
  6. The alternative technique in binary conversion is dividing the decimal value (quotient) from the base value (divisor) and documenting the R-values, working from the bottom-up until the dividend reaches 0
  7. Prefixes are used to represent large numbers for N2 and N10 values
  8. Bytes are displayed as two hexadecimal digits, or a nibbles
  9. When converting N2 to N16, always begin with nibbles from the LSB
  10. Each ASCII character is represented using one byte


Review Questions:

  1. How many bits are in a byte? in a nibble?
  2. What is the process to convert N10 to N2 and vice versa?
  3. What is the process to convert N16 to N10 and N2?
  4. When using the long division method in converting decimal to binary values, where is the MSB and LSB located?
  5. How do you convert data storage (B) to time based on data rates (bps)?
  6. Using the ASCII table, how do you convert ASCII values to hex, dec, bin?


References

  1. "JP 3-12, Cyberspace Operations," Department of Defense, Jun. 2018. [Online]. Available: https://irp.fas.org/doddir/dod/jp3_12.pdf
  2. G. England, "Cyberspace definition memo," U.S. Department of Defense, May 12, 2008. [Online]. Available: https://www.wired.com/2008/05/pentagon-define/
  3. A. S. Tanenbaum, Structured Computer Organization, 6th ed. Upper Saddle River, NJ: Prentice Hall, 2016.
  4. W. Stallings, Computer Organization and Architecture, 10th ed. Boston, MA: Pearson, 2015.
  5. R. H. Lewis and G. S. Hoover, Introduction to Computing Systems: From Bits and Gates to C and Beyond, 2nd ed. New York: McGraw-Hill, 2018.