Difference between revisions of "Number Systems"

From Coder Merlin
Line 206: Line 206:


== Exercises ==
== Exercises ==
=== Quiz A:  From Decimal ===
{{W1011-Exercises}}
<quiz shuffleanswers=true display=simple>
{
Convert 79<sub>10</sub> to hexadecimal:
|type="()"}
+ 4F<sub>16</sub>
- 5F<sub>16</sub>
- 32<sub>16</sub>
- 7H<sub>16</sub>
 
{
Convert 79<sub>10</sub> to octal:
|type="()"}
+ 117<sub>8</sub>
- 121<sub>8</sub>
- 115<sub>8</sub>
- 119<sub>8</sub>
 
{
Convert 79<sub>10</sub> to binary:
|type="()"}
+ 0100 1111<sub>2</sub>
- 0101 1111<sub>2</sub>
- 0110 1000<sub>2</sub>
- 0110 1010<sub>2</sub>
 
{
Convert 887<sub>10</sub> to hexadecimal:
|type="()"}
+ 03 77<sub>16</sub>
- 04 79<sub>16</sub>
- 02 79<sub>16</sub>
- 03 79<sub>16</sub>
 
{
Convert 887<sub>10</sub> to octal:
|type="()"}
+ 001 567<sub>8</sub>
- 002 567<sub>8</sub>
- 001 277<sub>8</sub>
- 000 367<sub>8</sub>
 
{
Convert 887<sub>10</sub> to binary:
|type="()"}
+ 0011 0111 0111<sub>2</sub>
- 0011 0111 1111<sub>2</sub>
- 0111 0111 0111<sub>2</sub>
- 0000 0111 0111<sub>2</sub>
 
{
Convert 7,583<sub>10</sub> to hexadecimal:
|type="()"}
+ 1D 9F<sub>16</sub>
- 1E 9F<sub>16</sub>
- D1 8F<sub>16</sub>
- D1 9F<sub>16</sub>
 
{
Convert 7,583<sub>10</sub> to octal:
|type="()"}
+ 016 637<sub>8</sub>
- 016 537<sub>8</sub>
- 116 237<sub>8</sub>
- 216 637<sub>8</sub>
 
{
Convert 7,583<sub>10</sub> to binary:
|type="()"}
+ 0001 1101 1001 1111<sub>2</sub>
- 0010 1101 1001 1111<sub>2</sub>
- 0001 1101 1011 1111<sub>2</sub>
- 0001 1101 1001 1110<sub>2</sub>
 
{
Convert 9,040<sub>10</sub> to hexadecimal:
|type="()"}
+ 23 50<sub>16</sub>
- 32 70<sub>16</sub>
- 23 58<sub>16</sub>
- 23 4E<sub>16</sub>
 
{
Convert 9,040<sub>10</sub> to octal:
|type="()"}
+ 021 520<sub>8</sub>
- 021 720<sub>8</sub>
- 021 525<sub>8</sub>
- 023 520<sub>8</sub>
 
{
Convert 9,040<sub>10</sub> to binary:
|type="()"}
+ 0010 0011 0101 0000<sub>2</sub>
- 0011 0011 0101 0000<sub>2</sub>
- 0010 0011 0101 0100<sub>2</sub>
- 0010 0011 0111 0000<sub>2</sub>
 
</quiz>
 
=== Quiz B:  To Decimal ===
<quiz shuffleanswers=true display=simple>
{
Convert 1A C7<sub>16</sub> to decimal:
|type="()"}
+ 6,855<sub>10</sub>
- 5,855<sub>10</sub>
- 6,853<sub>10</sub>
- 6,845<sub>10</sub>
 
{
Convert 0E 8D<sub>16</sub> to decimal:
|type="()"}
+ 3,725<sub>10</sub>
- 5,725<sub>10</sub>
- 4,705<sub>10</sub>
- 3,723<sub>10</sub>
 
{
Convert 05 55<sub>16</sub> to decimal:
|type="()"}
+ 1,365<sub>10</sub>
- 1,765<sub>10</sub>
- 1,362<sub>10</sub>
- 1,705<sub>10</sub>
 
{
Convert 0D 40<sub>16</sub> to decimal:
|type="()"}
+ 3,392<sub>10</sub>
- 3,192<sub>10</sub>
- 3,502<sub>10</sub>
- 5,392<sub>10</sub>
 
{
Convert 24 DB<sub>16</sub> to decimal:
|type="()"}
+ 9,435<sub>10</sub>
- 7,435<sub>10</sub>
- 9,135<sub>10</sub>
- 9,735<sub>10</sub>
 
{
Convert 7F FD<sub>16</sub> to decimal:
|type="()"}
+ 32,765<sub>10</sub>
- 32,767<sub>10</sub>
- 31,765<sub>10</sub>
- 33,665<sub>10</sub>
 
{
Convert 001 004<sub>8</sub> to decimal:
|type="()"}
+ 516<sub>10</sub>
- 506<sub>10</sub>
- 536<sub>10</sub>
- 616<sub>10</sub>
 
{
Convert 007 664<sub>8</sub> to decimal:
|type="()"}
+ 4,020<sub>10</sub>
- 2,020<sub>10</sub>
- 4,030<sub>10</sub>
- 4,120<sub>10</sub>
 
{
Convert 167 220<sub>8</sub> to decimal:
|type="()"}
+ 61,072<sub>10</sub>
- 60,072<sub>10</sub>
- 57,192<sub>10</sub>
- 57,102<sub>10</sub>
 
{
Convert 020 632<sub>8</sub> to decimal:
|type="()"}
+ 8,602<sub>10</sub>
- 8,622<sub>10</sub>
- 8,612<sub>10</sub>
- 8,592<sub>10</sub>
 
{
Convert 160<sub>8</sub> to decimal:
|type="()"}
+ 112<sub>10</sub>
- 102<sub>10</sub>
- 92<sub>10</sub>
- 116<sub>10</sub>
 
{
Convert 0100 0000 0011<sub>2</sub> to decimal:
|type="()"}
+ 1,027<sub>10</sub>
- 1,023<sub>10</sub>
- 1,037<sub>10</sub>
- 1,127<sub>10</sub>
 
{
Convert 0010 0010<sub>2</sub> to decimal:
|type="()"}
+ 34<sub>10</sub>
- 134<sub>10</sub>
- 24<sub>10</sub>
- 114<sub>10</sub>
 
{
Convert 1010 0111 0110 1001<sub>2</sub> to decimal:
|type="()"}
+ 42,857<sub>10</sub>
- 32,807<sub>10</sub>
- 42,807<sub>10</sub>
- 32,857<sub>10</sub>
 
{
Convert 1110 0011 1010 0010<sub>2</sub> to decimal:
|type="()"}
+ 58,274<sub>10</sub>
- 57,274<sub>10</sub>
- 58,174<sub>10</sub>
- 58,074<sub>10</sub>
 
{
Convert 1110 1110 1001 0000<sub>2</sub> to decimal:
|type="()"}
+ 61,072<sub>10</sub>
- 60,072<sub>10</sub>
- 61,172<sub>10</sub>
- 60,074<sub>10</sub>
 
{
Convert 0001 1011 1111 1110<sub>2</sub> to decimal:
|type="()"}
+ 7,166<sub>10</sub>
- 7,266<sub>10</sub>
- 7,168<sub>10</sub>
- 7,156<sub>10</sub>
 
</quiz>


== References ==
== References ==
* [https://en.wikipedia.org/wiki/Positional_notation Positional Notation] (Wikipedia)  
* [https://en.wikipedia.org/wiki/Positional_notation Positional Notation] (Wikipedia)  
* [https://en.wikipedia.org/wiki/Radix Radix] (Wikipedia)
* [https://en.wikipedia.org/wiki/Radix Radix] (Wikipedia)

Revision as of 19:13, 18 July 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Positional Notation[edit]

Positional notation (sometimes called place-value notation) is a method of encoding numbers. It differs from other notations (such as Roman numerals) in that it uses the same symbol for different orders of magnitude depending on its position. For example, consider the number 23. The “3” indicates 3 ones, because it is in the ones position. The “2”, however, indicates 2 tens, because it is in the tens position. We know the value of a position by its location within the number. As we move left in a number, each position is valued at ten times the prior position. It might help if we label each position using power notation. Consider the number 123:

Positional Notation.png

The “3” is the right-most, and therefore the lowest-valued position, representing “ones” with a position multiplier of 100 (that is, 10 raised to the zero power, or 1). The “2” is located one position to the left, so we multiply by 10 again giving us a position multiplier of 101 (that is, 10 raised to the first power, or 10). Finally, the “1” is located one position to the left, so we again multiply by 10 giving us a position multiplier of 102 (that is, 10 raised to the second power, or 100). By multiplying each digit by its corresponding position multiplier, we can obtain the value of the entire number:

1 * 102 + 2 * 101 + 3 * 100 =
100 + 20 + 3 =
123

While we generally understand the mechanics of this process in the decimal system, thinking about how it actually works will enable us to consider other systems.

Number Base[edit]

The radix or base is the number of unique digits, including zero, used to represent numbers in a positional numeral system. The base is normally written as a subscript to the right of the number. For example, the decimal number 123 would formally be written as (123)10
Note that the parentheses are sometimes not written: 12310
In the case of decimal (base 10) numbers, the subscripted 10 is often assumed and not written.

Decimal System[edit]

The decimal system is the system with which we are most familiar. It is a decimal system because it contains ten unique digits:

0 1 2 3 4 5 6 7 8 9

For any (integer) value larger than 9, we’re required to use positional notation. Please keep in mind that “10” is not a digit. Rather, it’s a number consisting of two digits, a “1” in the tens (101) position and a “0” in the ones position (100).

Octal System[edit]

The octal system uses eight unique digits to represent a number:

0 1 2 3 4 5 6 7

Let’s consider the value of an octal number: 47358

What is the decimal value of this number? We use exactly the same method that we use for knowing the value in any system:

Digit at position: 4 7 3 5
Position multiplier: 83 82 81 80
Position value: 4 • 83 7 • 82 3 • 81 5 • 80
2048 448 24 5

Note that in this case, the right-most digit is, as always, representative of units (ones), just as in any positional system. However, moving one digit to the left, because we’re now using an octal system, the position indicates the number of eights (not tens). The next position to the left indicates the number of sixty-fours (not hundreds) and the final position indicates the number of 512’s. As before, we multiply each digit by its corresponding position multiplier to obtain the value of the entire number:

4 • 83 + 7 • 82 + 3 • 81 + 5 • 80 =
2,04810 + 44810 + 2410 + 510 =
2,52510

Hexadecimal System[edit]

The hexadecimal (six and ten) uses sixteen digits to represent a number:

0 1 2 3 4 5 6 7 8 9 A B C D E F

Note that because we only have ten digits in our familiar decimal system, we use the letters A through F to represent the additional six digits in the hexadecimal system. Remember that these are digits, that is, A represents 10, B represents 11, and so on up to F which represents 15.

Let’s consider the value of a hexadecimal number: B59C16

What is the decimal value of this number?

Digit at position: B 5 9 C
Position multiplier: 163 162 161 160
Position value: B • 163 5 • 162 9 • 161 C • 160
45,056 1280 144 12

As always, we multiply each digit by its corresponding position multiplier to obtain the value of the entire number:

B • 163 + 5 • 162 + 9 • 161 + C • 160 =
45,05610 + 128010 + 14410 + 1210 =
46,49210

Binary System[edit]

The binary system (two) uses two digits to represent a number:

0 1

Let’s consider the value of a binary number: 1011 10102
What is the decimal value of this number?

Digit at position: 1 0 1 1 1 0 1 0
Position multiplier: 27 26 25 24 23 22 21 20
Position value: 1 • 27 0 • 26 1 • 25 1 • 24 1 • 23 0 • 22 1 • 21 0 • 20
128 0 32 16 8 0 2 0

Multiplying each digit by its corresponding position multiplier to obtain the value of the entire number:

1 • 27 + 0 • 26 + 1 • 25 + 1 • 24 + 1 • 23 + 0 • 22 + 1 • 21 + 0 • 20 =
12810 + 010 + 3210 + 1610 + 810 + 010 + 210 + 010 =
18610

Formal Representation[edit]

Let x be a string of digits, such that:

Then, the value of in any particular base, , is calculated as:

The rightmost digit, is referred to as the least significant digit, or LSD. It is least significant because in terms of the overall value of the entire number, this digit will always have the least impact. Conversely, the leftmost digit, is referred to as the most significant digit, or MSD. It is most significant because in terms of the overall value of the entire number, this digit will always have the most impact.

Converting from Decimal to Another Base[edit]

To convert a decimal (base 10) number to any other base, we simply repeatedly divide by the base until we have a quotient of zero. Specifically, the dividend starts with the number that we want to convert, the divisor will always be the base. The remainder of each successive operation indicates the digit in the new base first at the right-most position and then moving left. The quotient of each step becomes the dividend of the subsequent step.

Let’s first try converting the number 2810 to octal (base 8):

The dividend is the decimal number that we want to convert, in this case 28. The divisor is the base to which we want to convert, in this case 8. The remainder indicates each successive digit. We stop the process when the quotient is 0.

Step Dividend Divisor Quotient Remainder
1 28 8 3 4
2 3 8 0 3

So, 2810 is 348. (Remember that we read the remainder from bottom to top.)

Let’s try converting the number 56710 to octal:

Step Dividend Divisor Quotient Remainder
1 567 8 70 7
2 70 8 8 6
3 8 8 1 0
4 1 8 0 1

So, 56710 is 10678.

Let’s try converting the number 63,21510 to hexadecimal:

Step Dividend Divisor Quotient Remainder
1 63215 16 3950 15
2 3950 16 246 14
3 246 16 15 6
4 15 16 0 15

So, 63,21510 is hexadecimal [15][6][14][15], or more conventionally, F6EF16.
(Remembering that in hexadecimal, we use the digit “F” for 15, “E” for 14, etc.)


Finally, let’s convert the number 53410 to binary:

Step Dividend Divisor Quotient Remainder
1 534 2 267 0
2 267 2 133 1
3 133 2 66 1
4 66 2 33 0
5 33 2 16 1
6 16 2 8 0
7 8 2 4 0
8 4 2 2 0
9 2 2 1 0
10 1 2 0 1

So, 53410 is 10 0001 01102

Customs[edit]

  • It is customary to separate groups of three decimal digits by commas. For example: 123,45610.
  • It is customary to separate groups to two hexadecimal digits by spaces and prefix a leading zero to what would otherwise be a single digit. For example: 01 2F16.
  • It is customary to separate groups of three octal digits by spaces and prefix leading zeros to pad to a three digit grouping. For example: 001 2378.
  • It is customary to separate groups of four binary digits by spaces and prefix leading zeroes to pad to a four digit grouping. For example: 0001 1011 11002.

Shortcut Conversions[edit]

ComingSoonIcon.png
Coming Soon
  • Conversions from/to binary, octal, and hexadecimal

Exercises[edit]

Template:W1011-Exercises

References[edit]