Computing Fundamentals: Course Instructor: Engr - Noshina Shamir Lecturer CPED

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

Computing Fundamentals

Course Instructor:
Engr.Noshina Shamir
Lecturer CPED

Number Systems
Number Systems are employed in arithmetic to
represent numbers by strings of digits. There are
two types of number systems:
Positional number systems:
The meaning of each digit depends on its position
in the number.
Example:
585.5 is a decimal number in positional code
5 hundreds plus 8 tens plus 5 units plus 5
tenths.

Decimal number system is said to be of base


or radix 10 because it uses 10 distinct digits (0
9) and the digits are multiplied by power of
10:
585.5 = 5x10^2 + 8x10^1 + 5x10^0 + 5x10^-1
Non-positional number systems?
Answer is in the notes of this slide.

Positional Number Systems


We can represent numbers in any number
system with base r
Number in positional code
(An-1An-2A1A0.A-1A-2A-m+1A-m)r
r is the base (radix) of the system, r {2, 3, , I}.
every digit Ai {0, 1, 2, , r-1}, where {0, 1, 2, ,r1} is the digit set.

. is called the radix point.


A^N-1 is referred to as the most significant digit.

A^-M is referred to as the least significant digit.


Number in base r expressed as power series of r
as shown in above equation.

Binary Number System


This is the system used for arithmetic in all digital
computers
Number in positional code
(bn-1bn-2b1b0.b-1b-2..b-m+1b-m)r
r = 2 is the base of the binary system.
every digit bi {0, 1}
the digits bi in a binary number are called bits
bn-1 is referred to as the most significant bit
(MSB).
b-m is referred to as the least significant bit (LSB).

Number in base 2 expressed


as power series of 2

Example: a number in the


binary number system

bn-1 2 ^n-1 + bn-2^ 2+n-2


++ b1 2^1 + b0 ^20 + b-1^
2-1 + b-2^ 2-2 ++ b-m+1
2^m+1+ b-m ^2-m

(1011.01)2=1*2^3+0*2^2
+1*2^1+1*2^0.0*2^1+1*2^-2
=8+0+2+1.0+.25
=(11.25)10

Burn this table into your memory

Other Useful Number Systems


Apart from the ordinary binary number
system, the octal (base-8) and the
hexadecimal (base-16) number systems are
useful for representing binary quantities
indirectly because their bases are powers of
two. These systems have a more compact
representation of binary quantities.

Octal number system

Hexadecimal number system

Another Important Table

Conversion from base r to Decimal


The conversion of a number in base r to
decimal number (base 10) is done by
expanding the number in power series and
adding all the terms as shown below:
(An-1An-2A1A0.A-1A-2A-m+1A-m)r =An-1
r^n-1 + An-2 r^n-2 ++ A1 r^1 + A0 r^0 + A-1
r^-1 + A-2 r^-2 ++ A-m+1 r^m+1 + A-m r^-m

Conversion from base 2 to base 10


Example of converting Binary (base 2) to
Decimal (base 10):
(1011.01)2 = 1x2^3 + 0x2^2 + 1x2^1 + 1x2^0 +
0x2^-1 + 1x2^-2
= 8 + 2 + 1 + 0.25
= (11.25)10
Convrert (101111.10)2 to base 10

Conversion from base5 to base10


Example of converting number in base 5 to
Decimal (base 10):
(132.4)5 = 1x5^2 + 3x5^1 + 2x5^0 + 4x5^-1
= 25 + 15 + 2 + 0.8
= (42.8)10
Convert (423.1)5 to base 10

Conversion from base 8 to base 10


Example of converting Octal (base 8) to
Decimal (base 10):
(127.4)8 = 1x8^2 + 2x8^1 + 7x8^0 + 4x8^-1
=64+16+7+.5
= (87.5)10
Convert (123.7)8 to base 10

Example of converting Hexadecimal (base 16)


to Decimal (base 10):
(B6F.4)16 = 11x16^2 + 6x16^1 + 15x16^0 +
4x16^-1
=2816+96+15+.25
= (2927.25)10
Convert (123.4)16 to base 10

Conversion from Decimal to base r


The conversion is done as
follows:

Example of converting Decimal (base


10) to Binary (base 2): (41.6875)10

1) If the number has a radix point then


separate the number into an integer part
and a fraction part, since the two parts
must be converted differently.
2) The conversion of a decimal integer
part to a number in base r is done by
dividing the integer part and all successive
quotients by r and accumulating the
remainders.
3) The conversion of a decimal fraction
part to a number in base r is done
by multiplying the fractional parts by r and
accumulating integers.

Converting the integer part (41)10 :


41/2 = 20 + 1/2 Remainder = 1 LSB
20/2 = 10 + 0/2 0
10/2 = 5 + 0/2 0
5/2 = 2 + 1/2 1
2/2 = 1 + 0/2 0
1/2 = 0 + 1/2 1 MSB
(41)10 = (101001)2
Converting the fraction part (0.6875)10 :
0.6875 x 2 = 1.3750 Integer = 1 MSB
0.3750 x 2 = 0.7500 0
0.7500 x 2 = 1.5000 1
0.5000 x 2 = 1.0000 1 LSB
(0.6875)10 = (0.1011)2
(41.6875)10 = (101001.1011)2

Other Conversions

Binary to Octal or Hexadecimal:


grouping bits starting from the radix point
(1101010.01)2 to Octal (groups of 3):
(001|101|010.010|)2 = (152.2)8
(1101010.01)2 to Hex (groups of 4):
(0110|1010.0100|)2 = (6A.4)16

Other Conversions

Octal to Binary:
convert each digit to binary using 3 bits
(475.2)8 = (100 111 101. 010)2
Hexadecimal to Binary:
convert each digit to binary using 4 bits
(7A5F.C)16 = (0111 1010 0101 1111. 1100)2
= (111101001011111.11)2
Hexadecimal to Octal
Hexadecimal to Binary to Octal
Octal to Hexadecimal
Octal to Binary to Hexadecimal

Positive Integer Numbers


Positive integers and the number zero can be
represented as unsigned binary numbers
using a byte or an n-bit word.
Magnitude representation number N in
binary having n bits.
Example: 00001001 ( represents integer
number 9 using 8 bits ).

Arithmetic Operations
Arithmetic operations
with numbers in base r
follow the same rules as
for decimal numbers.
Examples: addition,
subtraction, and
multiplication in base-2.
In Digital Computers
arithmetic operations are
done with the binary
number system (base-2) Binary Arithmetic.

Binary Codes
Digital system represent and manipulate not only
binary numbers, but also other discrete element
of information represented with a binary code(i-e
pattern of 0s and 1s).
An n-bit binary code is group of n bits that
assumes up to 2^n distinct combination of 1s
and 0s ,with each combination representing one
element of the set that is being encoded.
A set of four elements require combination of
two bits.

Binary Codes
The bit combination of an n-bit code is
determined from the count in binary 0 to 2^n-1.
Each element is assigned a unique binary bit
combination, no two elements can have the same
value; otherwise, code assignment will be
ambiguous.
Although the minimum number of bits required
to code 2^n distinct quantities in ,there is no
maximum number of bits that may be used for
binary code.

BinaryCoded Decimal (BCD)


A binary code will have some unassigned bit
combinations if the number of elements in the set is
not a multiple power of 2. The 10 decimal digits form
such a set.
A binary code that distinguishes among 10 elements
must contain at least four bits, but 6 out of the 16
possible combinations remain unassigned. Different
binary codes can be obtained by arranging four bits
into 10 distinct combinations.
This scheme is called binarycoded decimal and is
commonly referred to as BCD

BCD CODE

Table gives the fourbit code for one


decimal digit.
A number with k decimal digits will
require how many bits in BDC code?
Decimal 396 is represented in BCD with 12
bits.
A decimal number in BCD is the same as
its equivalent binary number only when
the number is between 0 and 9.
A BCD number greater than 10 looks
different from its equivalent binary
number, even though both contain 1s and
0s. Moreover, the binary combinations
1010 through 1111 are not used and have
no meaning in BCD. Consider decimal
185 and its corresponding value in BCD
and binary:
(185)10 = (0001 1000 0101)BCD =
(10111001)2

BCD CODE
The BCD value has 12 bits to encode the characters of the decimal value,
but the equivalent binary number needs only 8 bits.
It is obvious that the representation of a BCD number needs more bits
than its equivalent binary value. However, there is an advantage in the use
of decimal numbers, because computer input and output data are
generated by people who use the decimal system.
It is important to realize that BCD numbers are decimal numbers and not
binary numbers, although they use bits in their representation. The only
difference between a decimal number and BCD is that decimals are
written with the symbols 0, 1, 2, 9 and BCD numbers use the binary code
0000, 0001, 0010, 1001. The decimal value is exactly the same. Decimal
10 is represented in BCD with eight bits as 0001 0000 and decimal 15 as
0001 0101.
The corresponding binary values are 1010 and 1111 and have only four
bits.

BCD Addition
add the BCD digits as if they were binary numbers.
When the binary sum is equal to or less than 1001
(without a carry), the corresponding BCD digit is
correct.
However, when the binary sum is greater than or
equal to 1010, the result is an invalid BCD digit.
The addition of 6 = (0110)2 to the binary sum
converts it to the correct digit and also produces a
carry as required. This is because a carry in the most
significant bit position of the binary sum.

Consider the following three BCD


additions:

The addition of two ndigit unsigned BCD


numbers follows the same procedure.
Consider the addition of 184 + 576 = 760 in BCD:

Other decimal codes

The 8, 4, -2, -1 code is an example of


assigning both positive and negative
weights
to a decimal code.
Excess3 is an unweighted code in which
each coded combination is obtained
from the corresponding binary value
plus 3.
T he 2421 and the excess3 codes are
examples of selfcomplementing codes.
Such codes have the property that the
9s complement of a decimal number is
obtained directly by changing 1s to 0s
and 0s to 1s
Note that the BCD code is not
selfcomplementing.

Gray Code
The output data of many physical systems are
quantities that are continuous. These data must
be converted into digital form before they are
applied to a digital system. Continuous or analog
information is converted into digital form by
means of an analog todigital converter. It is
sometimes convenient to use the Gray code
shown in Table.
The advantage of the Gray code over the straight
binary number sequence is that only one bit in
the code group changes in going from one
number to the next.
The Gray code is used in applications in which the
normal sequence of binary numbers generated by
the hardware may produce an error or ambiguity
during the transition from one number to the
next.

APPLICATION OF GRAY CODE


If binary numbers are used, a
change, for example, from
0111 to 1000 may produce an
intermediate erroneous
number 1001 if the value of
the rightmost bit takes longer
to change than do the values
of the other three bits. This
could have serious
consequences for the machine
using the information. The
Gray code eliminates this
problem, since only one bit
changes its value during any
transition between two
numbers.

A typical application of the


Gray code is the
representation of analog data
by a continuous
change in the angular position
of a shaft. The shaft is
partitioned into segments,
and each segment is assigned
a number. If adjacent
segments are made to
correspond with the Graycode
sequence, ambiguity is
eliminated between the angle
of the shaft and the value
encoded by the sensor.

ASCII Character Code


Many applications of digital computers require the handling not only of
numbers, but also of other characters or symbols, such as the letters of
the alphabet. For instance, consider a hightech company with
thousands of employees. To represent the names and other pertinent
information, it is necessary to formulate a binary code for the letters of
the alphabet.
An alphanumeric character set is a set of elements that includes the 10
decimal digits, the 26 letters of the alphabet, and a number of special
characters. Such a set contains between 36 and 64 elements if only
capital letters are included, or between 64 and 128 elements if both
uppercase and lowercase letters are included. In the first case, we need a
binary code of six bits, and in the second, we need a binary code of
seven bits.
The standard binary code for the alphanumeric characters is the
American Standard Code for Information Interchange (ASCII), which uses
seven bits to code 128 characters.

ASCII Character Code

The seven bits of the code are


designated by b1 through b7,with b7
the most significant bit. The letter A,
for example, is represented in ASCII as
1000001 (column 100, row 0001).
The ASCII code also contains 94
graphic characters that can be
printed and 34 nonprinting
characters used for various control
functions.
The graphic characters consist of the
26 uppercase letters (A through Z),
the 26 lowercase letters (a through
z), the 10 numerals (0 through 9),
and 32 special printable characters,
such as %, *, and $.

ASCII Character Code


The 34 control characters
are designated in the ASCII
table with abbreviated
names.
There are three types of
control characters:
format effectors
information separators
communicationcontrol
characters

Format effectors are characters that control the layout of printing. They
include the familiar word processor and typewriter controls such as
backspace (BS), horizontal tabulation (HT), and carriage return (CR).
Information separators are used to separate the data into divisions such as
paragraphs and pages. They include characters such as record
separator(RS) and file separator (FS).
The communicationcontrol characters are useful during the transmission
of text between remote devices so that it can be distinguished from other
messages using the same communication channel before it and after it.
Examples of communicationcontrol characters are STX (start of text) and
ETX (end of text), which are used to frame a text message transmitted
through a communication channel.
ASCII is a sevenbit code, but most computers manipulate an eightbit
quantity as a single unit called a byte.

ASCII characters most often are stored one


per byte.

The extra bit is sometimes used for other purposes,


depending on the application.

For example, some printers recognize eightbit ASCII


characters with the most significant bit set to 0.

An additional 128 eightbit characters with the most


significant bit set to 1 are used for other symbols, such
as the Greek alphabet or italic type font.

You might also like