[go: up one dir, main page]

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

Com Fun CH 2

Chapter 2 covers number systems and binary arithmetic, explaining various number systems, their bases, and conversion methods. It aims to equip readers with the ability to differentiate between signed representations, perform arithmetic operations, and understand binary codes. The chapter includes practical examples and rules for converting between decimal, binary, octal, and hexadecimal systems.

Uploaded by

Mhica Laguer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views18 pages

Com Fun CH 2

Chapter 2 covers number systems and binary arithmetic, explaining various number systems, their bases, and conversion methods. It aims to equip readers with the ability to differentiate between signed representations, perform arithmetic operations, and understand binary codes. The chapter includes practical examples and rules for converting between decimal, binary, octal, and hexadecimal systems.

Uploaded by

Mhica Laguer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Computer Fundamentals and

Programming

Chapter 2

Number Systems and Binary


Arithmetic
Chapter 2

Number Systems and Binary Arithmetic


Introduction

This chapter explain the number system used in computers, learn about the digit symbols,
base, and representation forms of various number systems developed and used explain the
method of number system conversions add and subtract unsigned binary numbers.

Specific Objectives

After studying this chapter, the readers will be able to:

 Differentiate signed magnitude, 1’s complement, and 2’s complement representation of


binary numbers
 Subtract signed numbers in 1’s complement and 2’s complement representation
 Explain the technique of multiplication and division of binary numbers
 Explain binary codes and their classification

Duration
(Specify the number of hours allotted for this chapter/lesson.)

Chapter 2: Number Systems and Binary Arithmetic = 2 hours


(1 hours 30 minutes discussion; 30
minutes assessment)
Lesson Proper

WHAT IS A NUMBER SYSTEM?

A number system defines a set of values used to represent quantity. For example, the
number of mobile phones kept in a shop, the number of persons standing in a queue,
and the number of students attending a class.

There are many ways to represent the same numeric value. Long ago, humans used
sticks to count; they then learned how to draw pictures of sticks on the ground and
eventually on paper. So, the number 5 was first represented as: | | | | | (for five sticks).

Later on, the Romans began using different symbols for multiple numbers of sticks: | |
| still meant three sticks, but a V meant five sticks, and a X was used to represent ten of
them. Using sticks to count was a great idea at that time. And using symbols instead of
real sticks was much better.

One of the best ways to represent a number today is by using the modern decimal
system. Why? Because it includes the major breakthrough of using a symbol to
represent the idea of counting nothing.

About 1500 years ago, in India, zero (0) was first used as a number. It was later used in
the Middle East as the Arabic, sifr. It was finally introduced in the West as the Latin,
zephiro. Soon it was seen how valuable the concept of zero was for all modern number
systems.

BASE VALUES

The base value of a number system is the number of different values the set has before
repeating itself. For example, decimal has a base of ten values, 0 to 9.

Binary = 2 (0, 1)
Octal = 8 (0 - 7)
Decimal = 10 (0 - 9)
Duodecimal = 12 (used for some purposes by the Romans)
Hexadecimal = 16 (0 - 9, A-F)
Vigesimal = 20 (used by the Mayans)
Sexagesimal = 60 (used by the Babylonians)

WEIGHING FACTOR

The weighting factor is the multiplier value applied to each column position of the
number. For instance, decimal has a weighting factor of TEN, in that each column to
the left indicates a multiplication value increase of 10 over the previous column on the
right, ie; each column moves to the left increases in a multiply factor of 10.

200 =
----- 0 * 100 = 0 * 1 = 0
------ 0 * 101 = 0 * 10 = 0
------- 2 * 102 = 2 * 100 = 200
-----
200 (adding these up)
-----

Lets consider another example of 312 decimal.

312 =
----- 2 * 100 = 2 * 1 = 2
------ 1 * 101 = 1 * 10 = 10
------- 3 * 102 = 3 * 100 = 300
-----
312 (adding these up)
-----

TYPES OF NUMBER SYSTEM

There are several types number systems. Table 2.1 shows a list of number systems with
their base and sets of valid digits.

 Decimal Number System (Base -10)

Most people today use decimal representation to count. This number system uses TEN
different symbols to represent values. In the decimal system there are 10 digit symbols
0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 with 0 having the least value and 9 having the greatest
value. For a number represented in decimal system, the digit on the extreme left has
the greatest value, whereas the digit on the extreme right has the least value.

Each position to the left increases by a weight of 10.

Example:
 Binary Number System (Base -2)

The binary number system uses TWO symbols to represent numerical values. These
are 0 and 1 with 0 having the least value and 1 having the greatest value. Number
representation in the binary system is similar to that in the decimal system, in which
the digit on the extreme left represents the greatest value and is called the most
significant digit (MSD), whereas the digit on the extreme right is known as the least
significant digit (LSD). Each position to the left increases by a weight of 2.

Example:

In a computer, a binary digit representing a binary value (0 or 1) is called a BIT. That


is, each digit in a binary number is called a bit, 4 bits form a NIBBLE, 8 bits form a
BYTE, two bytes form a WORD and two words form a DOUBLE WORD (rarely
used).

An n-bit number can represent 2n different number values, for example,


for an 8-bit number, 28 = 256 different values may be represented.

 Octal Number System (Base -8)

The octal number system uses EIGHT-digit symbols to represent numbers. The
symbols are 0, 1, 2, 3, 4, 5, 6, and 7 with 0 having the least value and 7 having the
greatest value.

The number representation in the octal system is done in the same way as in the decimal
system, in which the digit on the extreme left represents the most significant digit.

Each position to the left increases by a weight of 8. Thus,


 Hexadecimal Number System (Base -16)

The hexadecimal number system uses SIXTEEN symbols to represent numbers. The
symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F with 0 having the least value
and F having the greatest value. Number representation in hexadecimal system is done
in the
same way as in the decimal system, in which the symbol on the extreme left represents
the most significant digit.

Each position to the left increases by a weight of 16. Thus,

The hexadecimal system is often used to represent values (data and memory addresses)
in computer systems. Table 2.2 shows the representation of decimal numbers ranging
from 0 to 15 in binary, octal, and hexadecimal number systems.
COMMON RULES OF NUMBER SYSTEMS
All number systems follow the following set of rules:

 Rule 1 The number of digit symbols available in a number system is equal to the base.

Examples:

For the decimal system having base 10, there are 10-digit symbols 0 through 9.
For the binary system having base 2, there are 2 digits symbols 0 and 1.

 Rule 2 The value of the largest digit symbol is one less than the base.

Examples:

Decimal system—largest digit = 10 – 1 = 9


Binary system—largest digit = 2 – 1 = 1

 Rule 3 Each position multiplies the value of the digit symbol by the base raised to the
power of the value equal to the digit symbol position.

Examples:

Decimal system—consider the number


125 = 1 × 102 + 2 × 101 + 5 × 100

 Rule 4 A carry from one position to the next increases its weight base times.

Examples:

Decimal system—consider the number


5—5 = 5 × 100 or 5 ones.
Moving the number, one place, to the left, it becomes—
5 × 101 or 5 tens or 50.

Binary system—consider the number


1—1 = 1 × 20 or 1 one.
Moving the number, one place, to the left, it becomes—
1 × 21 or two 1’s or 10

To avoid confusion, often a subscript is used with a number to indicate the number
system base. For example,

162h ‘h’ means hexadecimal 162o ‘o’ means octal


16216 16 means base-16 1628 8 means base-8
162d ‘d’ means decimal 101b ‘b’ means binary
16210 10 means base-10 1012 2 means base-2
NUMBER SYSTEM CONVERSIONS

 Decimal to Binary

There are a number of ways to convert between decimal and binary. Let’s start with
converting the decimal value 254 to binary.

Method 1

Divide the number by 2, then divide what's left by 2, and so on until there is nothing
left (0). Write down the remainder (which is either 0 or 1) at each division stage. Once
there are no more divisions, list the remainder values in reverse order. This is the
binary equivalent.

254 / 2 giving 127 with a remainder of 0


127 / 2 giving 63 with a remainder of 1
63 / 2 giving 31 with a remainder of 1
31 / 2 giving 15 with a remainder of 1
15 / 2 giving 7 with a remainder of 1
7 / 2 giving 3 with a remainder of 1
3 / 2 giving 1 with a remainder of 1
1 / 2 giving 0 with a remainder of 1

thus, the binary equivalent is 11111110

Another example, 132 decimal

132 / 2 giving 66 with a remainder of 0


66 / 2 giving 33 with a remainder of 0
33 / 2 giving 16 with a remainder of 1
16 / 2 giving 8 with a remainder of 0
8 / 2 giving 4 with a remainder of 0
4 / 2 giving 2 with a remainder of 0
2 / 2 giving 1 with a remainder of 0
1 / 2 giving 0 with a remainder of 1

thus, the binary equivalent is 10000100

Method 2

Each column represents a power of 2, so use this as a basis of calculating the number.
It is sometimes referred to as the 8:4:2:1 approach.

Write down the binary number. Where a 1 appears in the column, add the column value
as a power of 2 to a total.

Weighting 8 4 2 1 Answer
Binary 1 0 1 1 11
Example:

Converting the decimal number 247 into its binary equivalent. The largest power of 2
that is less than 247 is 27 = 128. Form the table with the weighting factor in the columns
in the order shown, with 128 being the most significant weight. Put 1 in the digit
position with weighting factor 128.

Hence, 247 in base 10 is the same as 11110111 in base 2.


 Binary to Decimal

To express the value of a given binary number as its decimal equivalent, sum the binary
digits after each digit has been multiplied by its associated weight.

Example:

 Decimal to Octal

To convert from decimal whole numbers to octal, the systematic approach called the
repeated-division-by-8 method is used. This method is explained by the following
example.

Example:
 Octal to Decimal

To express the value of a given octal number as its decimal equivalent, add the octal
digits after each digit has been multiplied by its associated weight.

 Octal to Binary

Since each octal digit can be represented by a three-bit binary number (see Table 2.3),
it is very easy to convert from octal to binary. Simply replace each octal digit with the
appropriate three-bit binary number as indicated in the following example.

Example:

Converting the octal number 236700321 to its equivalent binary number.


 Binary to Octal

Converting a binary number to an octal number is a simple process. Break the binary
digits into groups of three starting from the binary point and convert each group into
its appropriate octal digit. For whole numbers, it may be necessary to add zeros as the
MSB, in order to complete a grouping of three bits. Note that this does not change the
value of the binary number.

Example:

 Decimal to Hexadecimal

The decimal number to be converted is divided by 16 until the quotient is 0. The


hexadecimal number is formed from the remainders.

Example:

Starting with the last remainder, convert the remainders into hexadecimal numbers:
1 5 11 14 10 = 15BEA = the hexadecimal number.

 Hexadecimal to Decimal

To convert a hexadecimal to decimal, begin by multiplying each of the hexadecimal


digits by their positional weight values as expressed in decimal. Then the resulting
values are added to obtain the value of the decimal number.

Example:

Converting the hexadecimal number A4D31 to its equivalent decimal number. The
decimal value of each digit in relation to its positional weight value is evaluated first:
 Hexadecimal to Binary

As each hexadecimal digit can be represented by a four-bit binary number (see Table
2.4), it is very easy to convert from hexadecimal to binary. Simply replace each
hexadecimal digit with the appropriate four-bit binary number as indicated in the
following examples.
Example:
Converting 123416 to a binary number.

Example:
Converting 37B16 to a binary number.

Example:
Converting the hexadecimal number AF376 to its equivalent binary number.

 Binary to Hexadecimal
Hexadecimal system works very much like the octal system, except that each digit
needs exactly four bits to represent it. This means the binary number has to be divided
into groups of four digits, again starting from the digit at the extreme right. The
equivalent hexadecimals for each set of four digits are then written. For whole numbers,
it may be necessary to add zeroes as the MSB in order to complete a grouping of four
bits. Note that this addition does not change the value of the binary number.

Converting the binary number 1111011101101011011 to its equivalent


hexadecimal number.
The conversion is done as follows:

A leading zero had to be added for the most significant group to have
four bits.

 Hexadecimal to Octal, Octal to Hexadecimal


To convert from hexadecimal to octal, each digit of the hexadecimal number is written
as its equivalent four-bit binary number. The resulting binary number is divided into
groups of three binary digits. Then corresponding octal numbers for each of these
groups are written.
Example:

Converting the hexadecimal number AF35D02 to its equivalent octal number. The
given number is rewritten by replacing the hexadecimal digits by their equivalent four-
bit binary numbers.

The binary number is regrouped as three-bit binary numbers that are replaced with
octal symbols.

Therefore, we see that AF35D0216 = 12746564028

Example:

Converting the octal number 1273244 to its equivalent hexadecimal. The given number
is written by replacing the octal digits with equivalent three-bit binary numbers.

The binary number is regrouped as four-bit binary numbers that are replaced with
hexadecimal symbols.
Therefore, we see that 12732448 = 2BF6A416.

 However, there are easier conversion methods. Some ways to perform conversion
between the bases are as follows.

Any base to decimal Use expanded notation. Write down each digit as a product of
a power of the base and add them all.

Decimal to any base Use the division method. Divide the decimal number repeatedly
with the base, writing down the remainder at each step. When the quotient becomes
zero, the string of remainders is the number in the new base.

Octal to hexadecimal or vice versa Use binary as an intermediate form.

BINARY ARITHMETIC

Binary arithmetic is essential part of all the digital computers and many other digital
systems.

 Binary Addition

It is a key for binary subtraction, multiplication, division. There are four rules of binary
addition.

In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is written in the
given column and a carry of 1 over to the next column.
Example – Addition

 Binary Subtraction

Subtraction and borrow, these two words will be used very frequently for the binary
subtraction. There are four rules of binary subtraction.

Example – Subtraction

 Binary Multiplication

Binary multiplication is similar to decimal multiplication. It is simpler than decimal


multiplication because only 0s and 1s are involved. There are four rules of binary
multiplication.
Example − Multiplication

 Binary Division

Binary division is similar to decimal division. It is called as the long division


procedure.

Example – Division

References/Additional Resources/Readings.

 Brown, B. (n.d.). Number Systems. Https://Www6.Uniovi.Es/Datas/Numbers.Htm.


https://www6.uniovi.es/datas/numbers.htm

 Pradip Dey, Manash Gosh “Computer Fundamentals and Programming in C Second


Edition” Oxford University Press 2006, 2013

You might also like