0% found this document useful (0 votes)
1 views89 pages

Number System

The document discusses digital computers and number systems, highlighting their importance in various fields and the flexibility of digital systems. It explains different number systems including binary, octal, and hexadecimal, as well as methods for converting between these systems and decimal. Additionally, it covers data representation, complements for subtraction, and signed binary numbers.
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)
1 views89 pages

Number System

The document discusses digital computers and number systems, highlighting their importance in various fields and the flexibility of digital systems. It explains different number systems including binary, octal, and hexadecimal, as well as methods for converting between these systems and decimal. Additionally, it covers data representation, complements for subtraction, and signed binary numbers.
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

Number Systems

Er. Riddhi K. Shrestha


Digital computer and digital system
❖Digital computers have made possible many scientific, industrial, and commercial
advances that would have been unattainable otherwise.
❖Computers are used in scientific calculations, commercial and business data processing,
air traffic control, space guidance, the educational field, and many other areas.
❖The most striking property of a digital computer is its generality.
❖It can follow a sequence of instructions, called program, that operates on given data.
❖The user can specify and change programs and/or data according to the specific need.
❖As a result of this flexibility, general-purpose digital computers can perform a wide
variety of information-processing tasks.
❖The general-purpose digital computer is the best-known example of a digital system.
Digital computer and digital system
Digital computer and digital system
❖ The memory unit stores programs as well as input, output, and intermediate data.
❖ The processor unit performs arithmetic and other data-processing tasks as specified by a program.
❖ The control unit supervises the flow of information between the various units. The control unit retrieves the instructions, one by
one, from the program that is stored in memory.
❖ For each instructions, the control unit informs the processor to execute the operation specified by the instruction.
❖ Both program and data are stored in memory.
❖ The control unit supervises the program instructions, and the processor manipulates the data as specified by the program.
❖ The program and data prepared by the user are transferred into the memory unit by means of an input device such as a keyboard.
❖ An output device, such as a printer, receives the result of the computations and the printed results are presented to the user.
❖ The input and output devices are special digital systems driven by electromechanical parts and controlled by electronic digital
circuits.
❖ Example: electronic calculator is similar to digital computer
Number system
❖We are all familiar with the decimal number system (Base 10).
❖Some other number systems that we will work with are:
❖Binary -> Base 2
❖Octal -> Base 8
❖Hexadecimal -> base 16
Characteristics of Number system
❖The digits are consecutive.
❖The number of digits is equal to the size of the base.
❖Zero is always the first digit.
❖The base number is never a digit.
❖When 1 is added to the largest digit, a sum of zero and a carry of one
results.
❖Numeric values determined by the have implicit positional values of
the digits.
Significant Digits
Binary: 11101101

Most significant bit Least significant bit

Hexadecimal: 1D63A7A

Most significant bit Least significant bit


Data Representation
❖Representation = Measurement
❖Most things in the “Real World” actually exist as a single,
continuously varying quantity Mass, Volume, Speed, Pressure,
Temperature
❖Easy to measure by “representing” it using a different thing that
varies in the same way E.g. Pressure as the height of column of
mercury or as voltage produced by a pressure transducer
❖These are ANALOG measurements
Data Representation
❖Convert ANALOG to DIGITAL measurement by using a scale of units
❖DIGITAL measurements
▪ In units – a set of symbolic values – digits
▪ Values larger than any symbol in the set use sequence of digits – Units, Tens,
Hundreds…
▪ Measured in discrete or whole units
▪ Difficult to measure something that is not a multiple of units in size. Eg
Fractions
Data Representation
❖Computers use digital representation
❖Based on a binary system
(uses on/off states to represent 2 digits).
❖ Many different types of data.
❖Examples?
❖ALL data (no matter how complex)
must be represented in memory as binary digits (bits).
Number Systems and computers
❖Computers store all data as binary digits, but we may need to convert
this to a number system we are familiar with.
❖Computer programs and data are often represented (outside the
computer) using octal and hexadecimal number systems because they
are a short hand way of representing binary numbers.
Number Systems - Decimal
❖The decimal system is a base-10 system.
❖There are 10 distinct digits (0 to 9) to represent any quantity.
❖For an n-digit number, the value that each digit represents depends
on its weight or position.
❖The weights are based on powers of 10.
1024 = 1*103 + 0*102 + 2*101 + 4*100 = 1000 + 20 + 4
Number Systems - Binary
❖Also called the “Base 2 system”.
❖The binary number system is used to model the series of electrical
signals computers use to represent information
▪ 0 represents the no voltage or an off state
▪ 1 represents the presence of voltage or an on state
❖The weights are based on powers of 2.
1011 = 1*23 + 0*22 + 1*21 + 1*20 = 8 + 0 + 2 + 1 = (11)10
Binary Additions
4 Possible Binary Addition Combinations:
Decimal to Binary Conversion
❖The easiest way to convert a decimal number to its binary equivalent
is to use the Division Algorithm
❖This method repeatedly divides a decimal number by 2 and records
the quotient and remainder
▪ The remainder digits (a sequence of zeros and ones) form the binary
equivalent in least significant to most significant digit sequence
Division Algorithm

Binary to Decimal Conversion
❖ The easiest method for converting a binary number to its decimal
equivalent is to use the Multiplication Algorithm
❖Multiply the binary digits by increasing powers of two, starting from
the right
❖Then, to find the decimal number equivalent, sum those products
Multiplication Algorithm
Classwork ??
❖Convert (41)10 to Binary.
❖Convert (00100111)2 to Decimal.
❖Convert (0.6875)10 to Binary.
❖Convert (41.6875)10 to Binary.
(0.6875)10 to Binary

Here, 0.6875 is multiplied by 2 to give an integer and a fraction.


The new fraction is multiplied by 2 to give a new integer and a new fraction.
This process is continued until the fraction becomes 0 or until the number of digits have sufficient accuracy.

Can we convert (0.1011)2 to decimal ?


Octal Number System
❖Also known as the Base 8 System
❖Uses digits 0 - 7
❖Readily converts to binary
❖Groups of three (binary) digits can be used to represent each octal
digit
❖Also uses multiplication and division algorithms for conversion to and
from base 10
Decimal to Octal Conversion
Classwork
❖Convert (153)10 to Octal.
❖Convert (321.45)10 to Octal.
❖Convert (153.513)10 to Octal.
Convert (321.45)10 to Octal.
For the integer part, we successively divide by 8 and collect the
remainders:
321 / 8 = 40 R 1.
40 / 8 = 5 R 0.
5 / 8 = 0 R 5.

There is no further to go, so the left-to-right sequencing of the octal


digits is obtained by reading the above remainders bottom to top, so
501.
Convert (321.45)10 to Octal.
For the fractional part, we successively multiply by 8 and pull off the integer parts:
0.45 × 8 = 3.6, so hold 3 and go to the next step with 0.6.
0.6 × 8 = 4.8, so hold 4 and go to the next step with 0.8.
0.8 × 8 = 6.4, so hold 6 and go to the next step with 0.4.
0.4 × 8 = 3.2, so hold 3 and go to the next step with 0.2.
0.2 × 8 = 1.6, so hold 1 and go to the next step with 0.6.

Now we are back to step 2, so steps 2 through 5 will repeat ad infinitum.


We now put the fractional octal part together with the left-to-right sequencing of
the octal digits being obtained by reading the held values from top to bottom, and
remembering to infinitely loop steps 2 through 5, so .3463146314631….
Putting the two pieces together, 321.4510=(501.34631)8
Convert (153.513)10 to Octal
Integer part (153)10 to octal is calculated using division algorithm:
We get, (153)10 = (231)8
For the fraction parts:

(153.513)10 = (231.4065176763)8
Octal to Decimal Conversion
Octal to Binary Conversion 3
(2 =8)
Classwork?
❖Convert (623)8 to Binary.
❖Convert (673.124)8 to Binary.
❖Convert (153.513)8 to Binary.
Hexadecimal Number System
❖Base 16 system
❖Uses digits 0-9 & letters A,B,C,D,E,F
❖Groups of four bits represent each base 16 digit
Decimal to Hexadecimal Conversion
Hexadecimal to Decimal Conversion
Binary to Hexadecimal Conversion
❖The easiest method for converting binary to hexadecimal is to use a
substitution code
❖Each hex number converts to 4 binary digits
Substitution Code
❖Convert 0101011010101110011010102 to hex using the 4-bit
substitution code :
Substitution Code
❖Substitution code can also be used to convert binary to octal by using
3-bit groupings:
Classwork?
❖Convert the hexadecimal number F3A7C2 to binary and octal.
Complements
❖Complements are used in digital computers for simplifying the
subtraction operation and for logical manipulation.
❖Conventional addition (using carry) is easily implemented in digital
computers. So more efficient to implement subtraction using addition
of complement of numbers.
❖There are two type of complements:
❖r’s complement
❖E.g 2's complement for base 2 and 10's complement for base 10
❖r-1’s complement
❖E.g. 1’s complement for base 2 and 9’s complement for base 10
Complements
❖(r-1)’s Complement
• Given a number N in base r having n digits,
• The (r-1)’s complement of N is defined as
(rn-1)-N
• For decimal numbers the base or r=10 and r-1 = 9,
• So the 9’s complement of N is (10n-1)-N
• 9999…. - N
-
9’s Complements: Examples
❖Find the 9’s complement of 546700 and 12389

The 9’s complement of 546700 is 999999-546700=453299

and the

9’s complement of 12389 is 99999-12389=87610.


1’s complement
❖For binary numbers, r=2 and r-2=1,
❖r-1’s complement is the 1’s complement.
❖The 1’s complement of N is (2n-1)-N.
❖Alternately, Switch all 0’s to 1’s and 1’s to 0’s
1’s Complement
r’s Complement
• Given a number N in base r having n digits,
• The r’s complement of N is defined as rn-N
• For decimal numbers the base or r=10,
• so the 10’s complement of N is 10n-N
• 100000….. - N
10’s Complement: Examples
• Given a number N in base r having n digits,
• The r’s complement of N is defined as rn-N
• For decimal numbers the base or r=10,
• so the 10’s complement of N is 10n-N
• 100000….. - N
Classwork
• Find 10’s complement of following?
• 012398
• 246700
2’s Complement
❖Step 1: Find 1’s complement of the number

❖Step 2: Add 1 to the 1’s complement


Classwork
• Find 2’s complement of 1011001?
• Find 2’s complement of 0001111?
Subtraction with r’s complement
• Subtraction of two +ve number (M-N) both of base r may be done as
follows:
▪ Add the Minuend M to the r’s complement of the subtrahend N.
• M + (rn-N) = M – N + rn
▪ Inspect the result obtained in step 1 for an end carry:
• If an end carry occurs, discard it.
• If an end carry does not occur, take the r’s complement of the number obtained in step
1 and place a –ve sign in front it.
Subtraction with r’s complement
• Subtract 72532 – 3250 using 10’s complement.
Subtraction with r’s complement
• Subtract 3250 - 72532 using 10’s complement.
Subtraction with r’s complement
• Subtract 1010100 - 1000100 using 2’s complement.

1
Subtraction with r’s complement
• Subtract 1000100 -1010100 using 2’s complement.
Classwork
• Given the two binary numbers X = 1010100 and Y = 1000011. Find X
– Y and Y – X using 2’s complement?
Subtraction with (r-1)’s Complement
• Subtraction with (r-1)’s complement
• Subtraction of two +ve number (M-N) both of base r may be done as
follows,
▪ Add the Minuend M to the (r-1)’ complement of the subtrahend N.
▪ Inspect the result obtained in step 1 for an end carry:
• If an end carry occurs, add 1 to least significant digit.
• If an end carry does not occur, take the (r-1)’s complement of the number obtained in
step 1 and place a –ve sign in front of it.
Subtraction with (r-1)’s Complement
• Subtract 72532 – 3250 using 9’s complement?
Subtraction with (r-1)’s Complement
• Subtract 3250 - 72532 using 9’s complement?
Subtraction with (r-1)’s Complement
• Subtract 1010100 - 1000100 using 1’s complement?
Subtraction with (r-1)’s Complement
• Subtract 1000100 - 1010100 using 1’s complement?
Classwork
• Given the two binary numbers X = 1010100 and Y = 1000011. Find X
– Y and Y – X using 1’s complement?
Signed Binary Numbers
• +ve integers including zero can be represented as a unsigned number.
• For representing –ve numbers we need a notation for –ve values.
• Due to H/W limitation computers must represent every thing in
binary forms.
• To do this sign is represented by a bit which is at the left most
position of the number.
• Sign bit 0 for +ve and 1 for –ve is used
Signed Binary Numbers
• Both signed and unsigned numbers consists of string of bits.
• The user determines whether the number is signed or unsigned, the
left most bit is the signed bit but rest of the bits represent the
number.
• If the number is assumed to be unsigned, then the left most bit of the
number is most significant bit of the number.
Signed Binary Numbers
• For example, 01001 is 9 in decimal (unsigned number) or +9 (signed
number) because the left most bit is 0.
• The string of bit 11001 is 25 in decimal when considered it as
unsigned.
• -9 when considered as a signed because of the 1 in the left most
position, which shows –ve. Other 4 bits shows the binary number.
• This whole is called the signed magnitude convention.
Signed Binary Numbers
• In this convention a number has magnitude and a symbol (+ or -) or a bit
(0,1).

• -25 is represented as 10011001


• This is used in ordinary arithmetic.
• When representing it in computer, a different technique is used ,
• Signed complement system
• In this system a –ve is represented by its complement
• 2’s complements is used to do the operation
• Consider 9 in binary with 8 bits,
• +9 is represented with 0 bit in left most position followed by binary equivalent of 9
which is 00001001.
Signed Binary Numbers
• There are three different ways to represents -9 with eight bits.
Signed Binary Numbers
• In signed magnitude -9 is obtained from +9 by changing the sign bit
from 0 to 1.
• In signed complement system -9 is obtained by taking the
complement of all the bits of +9 including the sign bit.
Binary Systems
CODES
• Digital system codes are
▪ BCD code
▪ Excess-3 code
▪ EBCDIC code
▪ Error detection code
▪ UNI CODE
▪ ASCII code
▪ Gray code
BCD – Binary Coded Decimal
• BCD is a convention for mapping binary numbers to decimal
numbers & for Decimal to binary numbers.
• When the decimal numbers are represented in BCD, each decimal
digit is represented by the equivalent BCD code.
• Example :BCD Representation of Decimal 6349
BCD
• 0-9 decimal digits need to be represented in a binary code which
must contain at least four bits.
▪ Four bits can make upto 16 different combinations.
▪ Only first 10 combinations are used. (0-9)
▪ BCD is different from binary representation.
▪ 15 in binary is 1111
BCD
EXCESS 3 CODE
• The excess-3 code is obtained by adding 3 (0011) to the
corresponding BCD equivalent binary number.
EBCDIC Code
• Extended BCD Interchange Code
• 8-bit code
• It contains the numbers from 0 to 28-1
• Developed by IBM
• Rarely used today
• IBM mainframes only
Error Detection and Correction
We need a mechanism of correcting the errors that occur
• It is not always possible or may prove to be expensive
• It is necessary to know if an error occurred
• If an occurrence of error is known, data may be retransmitted
• Data integrity is improved by encoding
• Encoding may be done for error correction.
Error Detection Code
• Error detection code detect errors during transmission of data
from one location to another.
• Error rate cannot be reduced to zero
• To achieve error-detection we use a parity bit.
• A parity bit is an extra bit included with a message to the total number of 1’s
transmitted either odd or even.
• Parity bit allows us only to detect the presence of one bit error in a group of
bits.
• It does not enable us to exactly locate the bit that changed.
• Parity bit scheme can be extended to locate the faulty bit In a block of
information.
Even Parity bit generator
Odd Parity bit generator
• Odd parity bit generator can be formed by inverting the output
of the Even parity bit generator.
Gray Code
• Gray coding is an important code and is used for its speed, it is also
relatively free from errors.
• Gray code is also known as reflected code.
• Gray coding avoids this since only one bit changes between
subsequent numbers.
• In pure binary coding then counting from 7 (0111) to 8 (1000)
requires 4 bits to be changed simultaneously.
• Gray code is used to represent the digital data when it is converted
from analog data.
Binary to Gray Code Conversion
• The MSB in the gray code is same as corresponding digit in binary
number.
• Going from left to right add each adjacent pair of binary digit to get
next gray code and discard carries.
• Example:
The Gray Code
Gray to Binary Conversion
• In Gray to binary the MSB in binary code is same as corresponding
digit in gray code.
• Add each binary digit generated to Gray digit in next adjacent position
and discard carry.
• Example:
UNICODE
• UNICODE is a 16-bit code for representing alphanumeric data.
• Developed by a consortia (An association or a combination, as of
businesses, financial institutions, or investors, for the purpose of
engaging in a joint venture.)
• With 16 bits, can represent 216 or 65536 different symbols.
• 16 bits = 2 Bytes per character.
• UNICODE used by Web browsers and Java these days.
ASCII CODE
• The standard binary code for representation of alphanumeric
characters is ASCII
• ASCII (American Standard for Information Interchange)
• It hands not only numbers but letters and special characters
• Uses 7 bits to code 128 characters
• In ASCII, every letter, number, and punctuation symbol has a
corresponding number, or ASCII code
ASCII CODE
• This code is a popular code used to represent information sent as
character- based data.
• It uses 7-bits to represent:
• 94 Graphic printing characters.
• 34 Non-printing characters
• Some non-printing characters are used for text format (e.g. BS =
Backspace, CR = carriage return)
• Other non-printing characters are used for record marking and flow
control (e.g. STX and ETX start and end text areas).
ASCII CODE
ASCII CODE
ASCII CODE
ASCII CODE
ASCII CODE
Happy Learning ☺☺

You might also like