0% found this document useful (0 votes)
30 views18 pages

Module 05 Number Systems

The document provides information about different number systems used in computing, including binary, octal, decimal, and hexadecimal. It discusses how to convert values between these number systems using place value and arithmetic operations. For example, it explains that in binary each bit has a place value of 2^n where n is the number of places from the right. It also covers how to perform addition, subtraction, multiplication and division on binary numbers.

Uploaded by

sarah caoile
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
30 views18 pages

Module 05 Number Systems

The document provides information about different number systems used in computing, including binary, octal, decimal, and hexadecimal. It discusses how to convert values between these number systems using place value and arithmetic operations. For example, it explains that in binary each bit has a place value of 2^n where n is the number of places from the right. It also covers how to perform addition, subtraction, multiplication and division on binary numbers.

Uploaded by

sarah caoile
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 18

MODULE 05

NUMBER SYSTEM AND


ARITHMETIC
OPERATIONS

LEARNING OBJECTIVES

1. Recognize different types of number systems as they relate to computers.


2. Identify and define unit, number, base/radix, positional notation, and most
and least significant digits as they relate to decimal, binary, octal,
and hexadecimal number systems.
3. Convert values from decimal, binary, octal, hexadecimal, and binary-coded
decimal number systems to each other and back to the other systems.
4. Add, subtract, multiply, and divide binary numbers

LOADING YOUR KNOWLEDGE

This unit introduce the topic of number systems with a focus on conversion of
binary numbers to decimal , binary, octal, hexadecimal, and binary-coded.
And at the end of this unit you will learn how to easily perform binary
arithmetic (addition, subtraction, multiplication and division) by hand.

57
LESSON 01
NUMBER SYSTEMS AND DATA REPRESENTATION

LET’S PROCESS

Number Systems and Data Representation

Inside today’s computers, data is represented as 1’s and 0’s. These 1’s and 0’s might
be stored magnetically on a disk, or as a state in a transistor, core, or vacuum tube. To
perform useful operations on these 1’s and 0’s we have to organize them together into
patterns that make up codes. First we will discuss numeric values for the codes, and then
ways that the codes represent textual values.
Each 1 and 0 is called a bit. 4 bits is called a nibble. 8 bits is called a byte.
16/32/64/128 bits is called a word. The number depends upon the number of bits that can
simultaneously be operated upon by the processor. Most processors today use 32 bits.
Since we only have 1’s and 0’s available, the number system generally used inside the
computer is the binary number system. We are used to the decimal number system. In
decimal, we have ten symbols (0-9) that we can use. When all of the symbols are used up,
we need to combine together two symbols to represent the next number (10). The most
significant digit becomes our first digit, and the least significant digit cycles back to 0. The
least significant digit increments until the symbols are used up, and which point the most
significant digit is incremented to the next larger digit. This is just the familiar process of
counting!
The same process applies to the binary number system, but we only have two symbols
available (0-1). When we run out of symbols, we need to combine them and increment the
digits just as we would in a decimal, base 10, number system: Let’s start counting to
illustrate:

Decimal Binary
0 0
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111
16 ?
17 ?

58
Binary to Decimal Conversion

The binary number system is positional where each binary digit has a weight based
upon its position relative to the least significant bit (LSB). To convert a binary number to
decimal, sum together the weights. Each weight is calculated by multiplying the bit by 2 i,
where i is the index relative to the LSB.

1 0 0 1 1
24 23 22 21 20
Weight = 1*20 + 1*21 + 0*22 + 0*23 + 1*24
= 1*1 + 1*2 + 0*4 + 0*8 + 1*16 = 1+2+16 = 19 (base 10, decimal)

LET’S TRY THIS

Convert Binary to Decimal

SELF–CHECK!

Convert Binary to Decimal

1. What is 1111 in base 10?


2. What is 10101 in base 10?

Decimal to Binary Conversion

To convert a decimal number to its equivalent binary number representation, the easiest
method is to use repeated division by 2. Each time, save the remainder. The first remainder
is the least significant bit. The last remainder is the most significant bit.

What is 19 in binary?

19 / 2 = 9 remainder 1 LSB
9/2=4 remainder 1
4/2=2 remainder 0
2/2=1 remainder 0
1/2=0 remainder 1 MSB

59
Our final number is 10011.

If using a calculator, watch to see if the quotient has a fraction. If it is 0.5 then the
remainder was 1, and repeat the process with the whole part minus the fraction.

LET’S TRY THIS

Convert Decimal to Binary

SELF–CHECK!

Convert Decimal to Binary

1. What is 83 in binary?
2. What is 100 in binary?

Octal Numbers

The octal number system uses base 8 instead of base 10 or base 2. This is sometimes
convenient since many computer operations are based on bytes (8 bits). In octal, we have 8
digits at our disposal, 0-7. Let’s do the counting again:

Decimal Octal
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 10
9 11
10 12
11 13
12 14
13 15
14 16

60
15 17
16 20
Octal to Decimal Conversion

Converting octal to decimal is just like converting binary to decimal, except instead of powers
of 2, we use powers of 8. That is, the LSB is 80, the next is 81, then 82, etc.

To convert 172 in octal to decimal:

1 7 2
82 81 80
Weight = 2*80 + 7*81 + 1*82
= 2*1 + 7*8 + 1*64
= 122 base 10

LET’S TRY THIS

Convert Octal to Decimal

SELF–CHECK!

Convert Octal to Decimal

1. What is 104 in octal converted to decimal?


2. What is 381 in octal converted to decimal?

Decimal to Octal Conversion

Converting decimal to octal is just like converting decimal to binary, except instead of
dividing by 2, we divide by 8. To convert 122 to octal:

122 / 8 = 15 remainder 2
15 / 8 = 1 remainder 7
1/8=0 remainder 1
= 172 octal

61
If using a calculator to perform the divisions, the result will include a decimal fraction
instead of a remainder. The remainder can be obtained by multiplying the decimal fraction
by 8. For example, 122 / 8 = 15.25. Then multiply 0.25 * 8 to get a remainder of 2.

LET’S TRY THIS

Convert Decimal to Octal

Octal to Binary, Binary to Octal

Octal becomes very useful in converting to binary, because it is quite simple. The
conversion can be done by looking at 3 bit combinations, and then concatenating them
together. Here is the equivalent for each individual octal digit and binary representation:

Octal Binary
1 001
2 010
3 011
4 100
5 101
6 110
7 111

To convert back and forth between octal and binary, simply substitute the proper pattern for
each octal digit with the corresponding three binary digits.

For example, 372 in octal becomes 010 111 010 or 010111010 in binary. 777 in
octal becomes 111 111 111 or 111111111 in binary.

The same applies in the other direction:

100111010 in binary becomes 100 111 010 or 472 in octal.

LET’S TRY THIS

Convert Octal to Binary

62
LET’S TRY THIS

Convert Binary to Octal

1. 2.

Octal Number: 2538 Octal Number: 3168

SELF–CHECK!

Answer the following questions.

1. What is 441 octal in binary?


2. What is 10110 binary in octal?

Since it is so easy to convert back and forth between octal and binary, octal is sometimes
used to represent binary codes. Octal is most useful if the binary code happens to be a
multiple of 3 bits long. Sometimes it is quicker to convert decimal to binary by first
converting decimal to octal, and then octal to binary.

Hexadecimal Numbering

The hexadecimal numbering system is the most common system seen today in
representing raw computer data. This is because it is very convenient to represent groups of
4 bits. Consequently, one byte (8 bits) can be represented by two groups of four bits easily
in hexadecimal.

Hexadecimal uses a base 16 numbering system. This means that we have 16 symbols
to use for digits. Consequently, we must invent new digits beyond 9. The digits used in hex
are the letters A,B,C,D,E, and F. If we start counting, we get the table below:

Decimal Hexadecimal Binary


0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110

63
15 F 1111
16 10 10000
17 11 10001
18 …

Hex to Decimal Conversion

Converting hex to decimal is just like converting binary to decimal, except instead of powers
of 2, we use powers of 16. That is, the LSB is 160, the next is 161, then 162, etc.

To convert 15E in hex to decimal:

1 5 E
162 161 160
Weight = 14*160 + 5*161 + 1*162
= 14*1 + 5*16 + 1*256
= 350 base 10

LET’S TRY THIS

Convert Hexadecimal to Decimal

SELF–CHECK!

Convert Hexadecimal to Decimal

1. What is F00 in hex converted to decimal?

Decimal to Hex Conversion

Converting decimal to hex is just like converting decimal to binary, except instead of dividing
by 2, we divide by 16. To convert 350 to hex:
350 / 16 = 21 remainder 14 = E
21 / 16 = 1 remainder 5
1 / 16 = 0 remainder 1
So we get 15E for 350.

Again, note that if a calculator is being used, you may multiple the fraction remainder by
16 to produce the remainder. 350/16 = 21.875. Then to get the remainder, 0.875 * 16 = 14.

64
LET’S TRY THIS

Convert Decimal to Hexadecimal

SELF–CHECK!

Convert Decimal to Hexadecimal

1. What is 33 in hex?

Hex to Binary Conversion, Binary to Hex

Going from hex to binary is similar to the process of converting from octal to binary. One
must simply look up or compute the binary pattern of 4 bits for each hex code, and
concatenate the codes together.

To convert AE to binary:

A = 1010
E = 1110
So AE in binary is 1010 1110

The same process applies in reverse by grouping together 4 bits at a time and then look up
the hex digit for each group.

Binary 11000100101 broken up into groups of 4:


0110 0010 0101 (note the 0 added as padding on the MSB to get up to 4 bits)
6 2 5
= 625 Hex

LET’S TRY THIS

Convert Hexadecimal to Binary

65
LET’S TRY THIS

Convert Binary to Hexadecimal

SELF–CHECK!

Answer the following questions.

1. What is B3 in binary?
2. What is 1101101111110101 in hexa?
3. How would you convert from Hex to Octal? E.g. convert B2F to octal.

BCD Code

When numbers, letters, words, or other pieces of data are represented by a special
group of symbols, then we say that the data is encoded. The group of symbols is called a
code. For example, Morse Code is a series of dashes and dots to represent letters.

Decimal numbers may be represented using binary notation. When this is done, it is
called a straight binary encoding.

Most systems use straight binary encoding to represent numbers. However, there are
times when it is easier to use another means to represent numbers, particularly when we
may want to retain some properties of decimal number systems. BCD, or binary coded
decimal, is one such representation.

BCD works by encoding each digit of a decimal number by its binary equivalent. Since
a decimal digit can be as large as 9, we need 4 bits to code it (1001). Here is an example
used to represent the decimal number 874:

8 = 1000
7 = 0111
4 = 0100

66
Note that 4 bits are always used for each digit. This results in the ‘wasted space’ of bit
patterns 9-F. If one of these patterns ever shows up when using BCD, it could be flagged as
an error condition.

Converting BCD to Decimal

LET’S TRY THIS

1. The BCD value 0001 0110 1001 0010 equals 169210.

BCD Nibble 0001 0110 1001 0010 = 0001 0110 1001 0010
Decimal Digit 1 6 9 2 = 169210

SELF–CHECK!

Answer the following questions.

1. What is 53 decimal in BCD?


2. What is 10010010 encoded in BCD in decimal?

Keep in mind that BCD is not a number system like binary, octal, decimal or
hexadecimal. Instead, it is an encoding scheme. It is actually equivalent to the decimal
system with an encoding to binary. A BCD number is NOT the same as its binary equivalent
number. The number 10 (decimal) could be represented as 1010 in binary encoding, but
would be represented as 0001 0000 in BCD.

The main advantage in using BCD is that it is easy to convert back and forth between
decimal.

Alphanumeric Codes

So far we have only been discussing the representation of numbers. We would also
like to represent textual characters. This includes letters, numbers, punctuation marks,
and other special characters like % or / that appear on a typical keyboard.

The most common code is ASCII, the American Standard Code for Information
Interchange. ASCII is comprised of a 7 bit code. This means that we have 2 7 or 128
possible code groups. This is plenty for English as well as control functions such as the
carriage return or linefeed functions.

Another code is EBCDIC, extended binary coded decimal interchange code.


EBCDIC was used on some mainframe systems but is now out of favor. The table at the back
of your assembly book has a complete listing of ASCII codes. A small sample is shown below.

67
Character ASCII Hex Decimal
A 41 65
B 42 66
C 43 67
Z 5A 90

Since most computers store data in bytes, or 8 bits, there is 1 bit that may go unused
(or used for parity, described below).

Could we represent something like Chinese in ASCII, which has many more than 128
characters?

One way to represent languages such as Chinese is to use a different code. UNICODE
is an international standard used to represent multiple languages. To address the
shortcomings of ASCII, UNICODE uses 16 bits per character. This allows 216 or 65536
characters. When this is insufficient, there are extensions to support over a million
characters. Most of the work in UNICODE has gone in efforts to define the codes for the
particular languages. If you would like more information, visit http://www.unicode.org.

There are Unicode definitions for lots of languages, even some that are made-up.
Some example Unicode characters for Tengwar (a script of Elvish from Tolkien lore) is
shown below.

Side note: A common problem with software development occurs when a product needs to
support foreign languages. Many products in the US are initially developed assuming ASCII.
However, if the product is successful and needs to support something like French or German,
it is often a difficult task to move the program from ASCII to UNICODE. Software developers
need to carefully take into account future needs and design the software appropriately. If it
is known up front that other languages may need to be supported, it is a relatively simple
matter to support UNICODE up front , or to remove dependencies on ASCII.

Identifying Code and Data

Although we might know the binary contents of memory, the actual usage of the
memory is not always clear. This is because in the von Neumann model, memory could
store data or instructions. Consequently, either the contents of memory could be a
computer instruction, or it could be data. If it is data, there is no way to tell if the data
represents ASCII encoding, a binary number, or maybe something else. A program must
keep track of its data and the type of representation used to avoid possible confusion. High
level languages like C++ or Java impose restrictions on the way variables and instructions
are manipulated (data type restrictions) but assembly language does not. In assembly
language, there are few restrictions, but the programmer is burdened with the responsibility
of taking care of many details.

68
LESSON 02
BINARY ARITHMETIC

LET’S PROCESS

Binary Arithmetic
Binary arithmetic includes the basic arithmetic operations of addition, subtraction,
multiplication and division. The following sections present the rules that apply to these
operations when they are performed on binary numbers.

Binary Addition
Binary addition is performed in the same way as addition in the decimal-system and
is, in fact, much easier to master. Binary addition obeys the following four basic rules:
0 0 1 1
+0 +1 +0 +1
0 1 1 10

The results of the last rule may seem some what strange, remember that these are
binary numbers. Put into words, the last rule states that binary one + binary one = binary
two = binary "one zero"
When adding more than single-digit binary number, carry into, higher order columns
as is done when adding decimal numbers. For example 11 and 10 are added as follows:
11
+ 10
101
In the first column (L S C or 2°) '1 plus 0 equal 1. In the second column (2 1) 1 plus 1
equals 0 with a carry of 1 into the third column (22).
When we add 1 + 1.+ 1 (carry) produces 11, recorded as 1 with a carry to the next
column.

LET’S TRY THIS

Add (a) 111 and 101 (b) 1010, 1001 and 1101.
Solution:

Binary Subtraction
Binary subtraction is just as simple as addition subtraction of one bit from another
obey the following four basic rules
0–0=0
1–1=0
1–0=1
10 – 1 = 1 with a transfer (borrow) of 1.

When doing subtracting, it is sometimes necessary to borrow from the next higher-
order column. The only it will be necessary to borrow is when we try to subtract a 1 from a 0.
In this case a 1 is borrowed from the next higher-order column, which leaves a 0 in that
column and creates a 10 i.e., 2 in the column being subtracted. The following examples
illustrate binary subtraction.

69
LET’S TRY THIS

Perform the following subtractions.


(a) 11 - 01 , (b) 11-10 (c) 100 - 011
Solution:

Part (c) involves to borrows, which handled as follows. Since a 1 is to be subtracted


from a 0 in the first column, a borrow is required from the next higher-order column.
However, it also contains a 0; therefore, the second column must borrow the 1 in the third
column. This leaves a 0 in the third column and place a 10 in the second column. Borrowing
a 1 from 10 leaves a 1 in the second column and places a 10 i.e, 2 in the first column:
When subtracting a larger number from a smaller number, the results will be negative.
To perform this subtraction, one must subtract the smaller number from the larger and
prefix the results with the sign of the larger number.

LET’S TRY THIS

Perform the following subtraction 101 – 111.


Solution:
Subtract the smaller number from the larger.
111
– 101
010
Thus 1 0 1 – 1 1 1 = - 010 = - 10

Binary multiplication
Binary multiplication is performed in the same manner as decimal multiplication. It is
much easier, since there are only two possible results of multiplying two bits. The Binary
multiplication obeys the four basic rules.

LET’S TRY THIS

Multiply the following binary numbers.

Solution:

70
Multiplication of fractional number is performed in the same way as with fractional
numbers in the decimal numbers.

LET’S TRY THIS

Perform the binary multiplication 0.01 x 11.


Solution:

Binary Division
Division in the binary number system employees the same procedure as division in the
decimal system, as will be seen in the following examples.

LET’S TRY THIS

Perform the following binary division.


(a) 110 ÷ 11 (b) 1100 ÷ 11
Solution:
(a) 10 (b) 100
11 110 11 11000
11 11
00 00
00 0 0_
00 00
00
00

Binary division problems with remainders are also treated the same as in the decimal
system, as illustrates the following example.

LET’S TRY THIS

Perform the following binary division:


(a) 1111 ÷ 110 (b) 1100 ÷ 101
Solution:
(a) 10. 1 (b) 10. 011
110 1 100.00
110 1 11 1.00 1 01
1 10 100
1 10 000
1 10 1000
000 101
110
101
1
(remainder)

71
iCONNECT

You can visit these links for additional information about the Number Systems and Binary
Arithmetic

1. Number Systems
https://www.youtube.com/watch?
v=L2zsmYaI5ww&list=PL0o_zxa4K1BXCpQbUdf0htZE8SS0PYjy-
2. Number Systems Introduction - Decimal, Binary, Octal, Hexadecimal & BCD Conversions
https://youtu.be/L2zsmYaI5ww?list=PL0o_zxa4K1BXCpQbUdf0htZE8SS0PYjy-
3. How To Convert Binary To Decimal
https://www.youtube.com/watch?
v=VLflTjd3lWA&list=PL0o_zxa4K1BXCpQbUdf0htZE8SS0PYjy-&index=2
4. Binary to Decimal Using Excel!
https://youtu.be/EJX6Ub_USWw?list=PL0o_zxa4K1BXCpQbUdf0htZE8SS0PYjy-

COMPILE YOUR KNOWLEDGE

 Each 1 and 0 is called a bit.


 4 bits is called a nibble.
 8 bits is called a byte.
 16/32/64/128 bits is called a word.
 Data is represented as 1’s and 0’s
 The binary number system is positional where each binary digit has a weight based
upon its position relative to the least significant bit (LSB).
 To convert a decimal number to its equivalent binary number representation,
the easiest method is to use repeated division by 2. Each time, save the
remainder. The first remainder is the least significant bit. The last remainder
is the most significant bit.
 The octal number system uses base 8 instead of base 10 or base 2. This is
sometimes convenient since many computer operations are based on bytes (8 bits). In
octal, we have 8 digits at our disposal, 0-7.
 Octal becomes very useful in converting to binary, because it is quite simple. The
conversion can be done by looking at 3 bit combinations, and then concatenating
them together.
 The hexadecimal numbering system is the most common system seen today in
representing raw computer data. This is because it is very convenient to
represent groups of 4 bits. Consequently, one byte (8 bits) can be represented
by two groups of four bits easily in hexadecimal.
 Decimal numbers may be represented using binary notation. When this is
done, it is called a straight binary encoding.
 Keep in mind that BCD is not a number system like binary, octal, decimal or
hexadecimal. Instead, it is an encoding scheme.
 The most common code is ASCII, the American Standard Code for Information
Interchange.
 Binary arithmetic includes the basic arithmetic operations of addition, subtraction,
multiplication and division.

DEBUG YOUR SKILLS

72
I. Answer the following questions. Write your solutions and your final answer in your Big
Notebook.

No No. DECIMAL TO OCTAL


DECIMAL TO BINARY
. 11 54
1 41 12 111
2 30 13 78
3 99 14 33
4 123 15 25
5 6 No. OCTAL TO DECIMAL
No 16 366
BINARY TO DECIMAL
. 17 70
6 1111 18 217
7 1101 19 37
8 100101 20 5
9 00111100
10 11111101No. DECIMAL TO HEXADECIMAL
21 154
22 2
23 25
24 32
25 99
No. HEXADECIMAL TO DECIMAL
26 DD
27 E2
28 B8
29 A1
30 FC

II. Add the following binary numbers. Write your solutions and your final answer in your
Big Notebook.

1.

2.

……….

III. Subtract the following binary numbers. Write your solutions and your final answer in
your Big Notebook.

1.

73
IV. Multiply the following binary numbers. Write your solutions and your final answer in
your Big Notebook.

V. Divide the following binary numbers. Write your solutions and your final answer in your
Big Notebook.

REFERENCES

1. https://www.pbte.edu.pk/text%20books/dae/math_123/Chapter_1.pdf
2. https://www.tutorialspoint.com/computer_logical_organization/pdf/
binary_arithmetic.pdf
3. http://www.maths.qmul.ac.uk/~ivan/MAE113/lect2.pdf
4. https://www.tutorialspoint.com/basics_of_computers/
basics_of_computers_number_system_conversion.htm
5. http://www.math.uaa.alaska.edu/~afkjm/cs221/handouts/datarep.pdf

74

You might also like