Module 2 - Part 1 - FOC
Module 2 - Part 1 - FOC
ule 2
Module 2
❑ The most fundamental number system in computing is binary, which only uses
the digits 0 and 1.
❑ There are different types of number systems in which the four main types are:
❑ The binary number system uses only two digits: 0 and 1. The numbers in this system have a base of 2.
❑ The binary system is applied internally by almost all latest computers and computer-based devices
because of its direct implementation in electronic circuits using logic gates.
❑ Every digit is referred to as a bit. binary number, the rightmost digit is called least significant bit
(LSB) and leftmost digit is called most significant bit (MSB). The binary number are represent like
(110101)2
1 1 0 0 1 1
MSB LSB
Binary Number System
❑ Binary number system conversion into decimal and decimal equivalent of this
number is sum of product of each digit with its positional value.
❑ Binary to Decimal conversation
►
Decimal Number System
❑ Decimal number system is a base 10 number system having 10 digits from 0 to 9. This means
that any numerical quantity can be represented using these 10 digits. Decimal number system is
also a positional value system. This means that the value of digits will depend on its position.
Let us take an example to understand this.
= 1000 + 200 + 30 + 4
= 123410
Decimal to Binary Conversion
► 1. Take any decimal number and divide it by “2". After dividing, you will get some results along
with the remainder.
► 2. If the decimal number chosen by you is even, then the result will be in a whole number and it
will give the remainder 0.
► 3. If the decimal number chosen by you is odd, then the number will not be divided fully and you
will get the remainder “1”.
► 4. Continue dividing the number till you get the quotient 0
► 5. Now place all the remainders in the series of Least Significant Bit (LSB) at the top and the
Most Significant bit (MSB) at the bottom.
Decimal to Binary Conversion
75/2 37 1 1 (LSB)
37/2 18 1 1
18/2 9 0 0
9/2 4 1 1
4/2 2 0 0 (75) 2 = 1001011
2/2 1 0 0
1/2 0 1 1 (MSB)
Binary Number System
► Decimal number system is the base 10 number system and uses the digits
from 0 to 9. Using these digits you can express any quantity.
► It is what we most commonly use.
► Decimal to Binary Conversion Techniques:
► Divide each bit by 2, keep track of the remainder 🡪odd –rem=1,even
rem=0
► Continue dividing the number till you get the quotient 0.
► Now place all the remainders in the series of Least Significant Bit
(LSB) at the top and the Most Significant bit (MSB) at the bottom.
► Example (125)10 = (1111101) 2
Binary operations
► Binary addition
► Binary subtraction
► Binary multiplication
► Binary division
Binary addition
0+0= 0
0+1= 1
1+0= 1
1+1= 10 (0 with a carry of 1)
1+1+1 = 11
Example
110101 + 11011
Solution:
110101
+ 11011
1010000
Addition of large binary numbers
Solve
1. (10101)2 + (10110)2
2. (10111)2 + (11000)2
3. 00111 + 01110 10101 (the value 21 = 16 + 4 + 1
Rules for binary subtraction
Subtraction of large binary numbers
❑ Integers are whole numbers or fixed point numbers. The radix point is fixed after
the LSB.
Example:
54533. 4573.55
❑ Unsigned Integers – that can represent only zero and positive numbers. The value of an
unsigned integer interpreted as the “magnitude of underlying binary pattern or the normal
way we convert binary to decimal.
All above numbers represent zero in different bit systems. The bit length of each system is different.
Integer Representation
❑ In a computer, integers and floating point numbers are treated differently and processed
separately.
❑ Floating point numbers are processed in a separate processor called floating point
processor.
❑ Computers use fixed number of bits to represent integers. Commonly use bit lengths are
8bit, 16bit, 32bit and 64bit.
❑ There are two types of integers
❑ Unsigned integers: can represent zero and positive numbers only
❑ Signed integers: can represent zero, positive and negative numbers.
Different ways to represent Signed Integer:
❑ There are three schemas (ways) to represent signed integers.
❑ Sign Magnitude representation
❑ 1’s complement representation
❑ 2’s complement representation
n-bit Unsigned Integers
❑ An n-bit pattern can represent 2n distinct integers. This range from 0 to (2n)-1
When you are programming you need to select the correct and
appropriate bit size to store integers. If you want to store small
numbers less than 255, you can select 8 bit number, selecting 32 bit
length to store small numbers is a waste of resources.
Signed Integers
Examples:
n=8 (8 bit number) and binary number is 0100 0001
Examples:
In this representation, the MSB is the sign bit and MSB=0 represent
positive and MSB=1 represent negative numbers. The remaining n-1 bits
represent the magnitude (value) of the integer.
❑ In positive integers, the value of the integer is the binary pattern (value) of
the n-1 bit magnitude. Same as Sign Magnitude Representation.
❑ For negative integers, the absolute value is the n-1 binary pattern value of
the inverse magnitude (complement).
In 2’s Complement Representation also the MSB is the sign bit 0 represent
positive and 1 represent negative integers.
★ For positive integers, the value of the integer equal to the magnitude of
n-1 binary pattern.
★ For negative integers, the absolute value of the integer equal to the
magnitude of the complement of n-1 binary pattern plus one.
0111
1000 (1’s complement)
+ 0001 (Add 1)
—-------
1001 (2’s complement)
Range of Numbers : (2’s Complement Method)
-n = 2’s complement of +n
65D 🡪 0100 0001B
-5D 🡪 1111 1011B -5 = 2’s complement of +5
65D + (-5D) 🡪 0011 1100B 🡪 60D OK within the range of -128 to +127
n-bit 2’s Complement Representation
Addition, Subtraction, Overflow and Underflow
Overflow and underflow happens when the result is not within the acceptable range
Example of Overflow: n=8, 127D + 2D = 129D (not within -128 and +127, exceed
maximum value)
Example of underflow: n=8, -125D – 5D = -130D (not within -128 and +127, below
the minimum value)
An n-bit 2’s complement integer can represent integers from -2(n-1) to +2(n-1)-1.
This can represent all the integers within the range without missing any intergers.
• Check the sign bit first. If sign bit = 0, the number is positive and the absolute
value if the binary value of remaining n-1 integers.
• If the sign bit = 1, the integer is negative. To get the absolute value;
• Invert remaining n-1 bits and add 1 or
• Scan from left until the first occurrence of 1. Flip all values from that point to
the left. Binary value of this pattern gives the absolute value of the negative
integer.
Example:
N=8 bit pattern = 1 100 0100 B
Negative number
Scan from right, until the first occurrence of 1, flip all values from that point to left
011 1100 B = 60 D
Represented negative value is -60 D
Binary value of 60 = 11 1100
60 =
0b111100
Represent -60 in 1’s complement form
60 in binary = 111100
60 in binary = 0011 1100
In this representation, we can represent numbers in any number of bits (powers of 2).
There are two parts in the representation. Sign and Magnitude, as the name implies.
If we want to represent a number in n number of bits,
★ the first bit always represents the sign of the number. That is, 0 for a positive number
and 1 for a negative number.
★ the remaining bits (n-1) represent the magnitude of the number in Binary.
★ e.g. If you want to represent +25 and -25 using 8 bits: (+25) 10 = 00011001 and (-25)10 =
10011001
★ Binary value of 25 = 11001
Complement
Since Binary number system has only 2 digits (0 and 1), the
complement of one digit is the other. i.e. the complement of 0 is 1
and vice versa.
► Complement of 0 = 1
► Complement of 1 = 0
One's Complement
In this representation, there is no specific bit to represent the sign, but the MSB (Most Significant
Bit) can be used to determine the sign of the number. i.e. MSB is 0 if the number is positive and 1 if
the number is negative. Binary numbers are used and also a specific bit size is used. (e.g. 8, 16,
32, etc. bits ) or (powers of 2).
e.g. Take the previous example again
1) If the number is positive
★ (+25)10
● Convert the number to binary
○ Convert the number to binary→ (11001)2
● Set the number to specific bit size
○ Set the number to specific bit size → (0001 1001)
● (+25)10
● Convert the number to binary → (11001)2
● Set the number to specific bit size → (0001 1001)
● (-25)10
● Convert the number to binary → (11001)2
● Set the number to specific bit size → (0001 1001)
● Get the complement of that value → (1110 0110)
● Add 1 to LSB → (1110 0110) + 1 = (1110 0111)
Two’s complement representation
In this diagram, (previous slide) the positive numbers begin at 000 and proceed in order around
the circle to the right. Negative numbers begin at 111 and proceed in order around the circle to
the left. The leftmost digit specifies whether the number is to be given a positive interpretation
(leftmost bit = 0) or a negative interpretation (leftmost bit = 1).
★ Two’s complement is widely used for representing signed numbers inside a computer.
64
► Numbers
► Whole number, fractional number, …
► Text
► ASCII code, unicode
► Audio
► Image and graphics
► video
Representing Numbers
► 64 bits: one for sign, some for mantissa, some for exp.
Floating point representation:
Binary numbers:
sign * mantissa * 2 exp
Convert 8.25 from decimal to binary
To convert decimal number 8.25, we convert its integer and
fraction part individually and then add them to get the For converting decimal fraction 0.25 to binary number,
equivalent binary number, as below: follow these steps:
To convert integer 8 to binary, follow these steps: Step 1: Multiply 0.25 by 2 keeping notice of the resulting
integer and fractional part. Continue multiplying by 2 until
Step 1: Divide 8 by 2 keeping notice of the quotient and the
you get a resulting fractional part equal to zero (we
remainder. Continue dividing the quotient by 2 until you get
calcuclate upto ten digits).
a quotient of zero.
Step 2: Then just write out the integer parts from the
Step 2: Then just write out the remainders in the reverse
results of each multiplication to get equivalent binary
order to get the equivalent binary number.
number.
8 / 2 = 4 with remainder 0
0.25 × 2 = 0 + 0.5
4 / 2 = 2 with remainder 0
0.5 × 2 = 1 + 0
2 / 2 = 1 with remainder 0
1 / 2 = 0 with remainder 1 Here is the answer to 0.25 decimal to binary number:
0.01
Here is the answer to 8 decimal to binary number:
1000
Therefore, decimal number 8.25 converted to binary is equal: 1000.01
Data storage units - bits, bytes, kilobytes
In data storage units, a "bit" is the smallest unit, a "byte" is made up of 8 bits, and a "kilobyte" is
made up of 1024 bytes; essentially, a kilobyte is a collection of 1024 bytes, which are each made
up of 8 bits.
● Bit: A single binary digit, either 0 or 1, representing the most basic unit of data storage.
● Byte: A group of 8 bits, allowing for more complex data representation.
● Kilobyte (KB): A unit containing 1024 bytes, often used to measure smaller file sizes.
Data storage units - bits, bytes, kilobytes
Memory is like an electronic scratch pad inside the computer. It is a storage unit to hold the data.
In the computer the data will be stored and retrieved in the form of bits and bytes. The byte will
store a single character such as a letter of the alphabet or a numeral.
● In a computer, one bit is equal to the smallest unit of data storage, which can be either a 0 or
a 1.
1) 8 BITS = 1 BYTE
2) 1024 BYTES = 1 KB
3) 1024 KB = 1 MB
4) 1024 MB = 1 GB
5) 1024 GB = 1 TB.
Representing Text 77
► Take English text for example
► Text is a series of characters
► letters, punctuation marks, digits 0, 1, …9, spaces, return (change a line), space, tab, …
Textual Information - To represent textual material in binary, the system assigns to each
printable letter or symbol in our alphabet a unique number (this assignment is called a
code mapping), and then it stores that symbol internally using the binary equivalent of
that number.
★ Initially, the most widely used code set for representing characters internally in a
computer system was ASCII, an acronym for the American Standard Code for
Information Interchange. ASCII is an international standard for representing textual
information that uses 8 bits per character, so it is able to encode a total of 2 8 = 256
different symbols.
★ These are assigned the integer values 0 to 255. However, only the numbers 32 to 126
have been assigned to printable characters. The remainder either are unassigned or
are used for representing non printing control characters such as tab, form feed, and
return. Figure 4.3 shows the ASCII conversion table for the numerical values 32–126.
Textual Information (ASCII and Unicode)
The code set called Unicode, developed in the early 1990s, has gained in
popularity because it uses, at a minimum, a 16-bit representation for
characters rather than the 8-bit format of ASCII. This means that it is able to
represent at least 216 5 65,536 unique characters instead of the 2 8 = 256 of
ASCII.
(Note: Unicode is a superset of ASCII. The decimal values 0–127 represent
exactly the same characters in both ASCII and Unicode.)
It might seem as though 256 characters should be more than enough to
represent all the textual symbols that we would ever need
—for example, 26 uppercase letters, 26 lowercase letters, 10 digits, and a few
dozen special symbols, such as + = − { } ] [\: ” ? > < . , ; % $ # @.
UNICODE
● Add that all together and it still totals only about 100 symbols, far less than the 256
that can be represented in ASCII.
● However, that is true only if we limit our text to Arabic numerals and the Roman
alphabet.
● The world is growing more connected all the time—helped along by computers,
networks, and the web—and it is critically important that computers are able to
represent and exchange textual information using the widest possible range of
alphabets.
● When we start assigning codes to symbols drawn from alphabets such as Russian,
Arabic, Chinese, Hebrew, Greek, Thai, Bengali, Sanskrit, Cherokee, Inuit, and Braille,
as well as mathematical symbols, linguistic marks such as the tilde, umlaut, and
accent grave, and numerous graphical symbols, it quickly becomes clear that ASCII
does not have enough room to represent them all.
Unicode
● Unicode, with its 16 bits and space for over 65,000 symbols, was
initially considered large enough to accommodate this enormous
range of text.
● However, it turned out that even 16 bits proved insufficient to
handle the exploding range of textual information being produced
around the world, and
● Unicode now includes a 32-bit variant in which each separate
character is represented using 32 binary digits, allowing for the
possibility of 232 distinct textual symbols, or about 4 billion!
● Currently Unicode has assigned formal mappings to more than
128,000 characters drawn from over 135 modern and historical
alphabets, including such rarities as Egyptian hieroglyphics.
83
ASCII code
● Capital letters :
A to Z : 65 to 90
● Small letters :
a to z : 97 to 122
● * 42 (multiplication)
● + 43 (plus / addition)
● - 45 (minus / subtract)
● / 47 (divide)
● < 60
● = 61
● > 62
86
► Unicode
► international/multilingual text character encoding system,
tentatively called Unicode
► Currently: 21 bits code space
► How many diff. characters?
► Encoding forms:
► UTF-8: each Unicode character represented as one to four 8-but
bytes
► UTF-16: one or two 16-bit code units
► UTF-32: a single 32-bit code unit
Binary Representation of Numeric and Textual
Information
★ Three alphanumeric codes are in common use. The three codes are
known as Unicode, ASCII (which stands for American Standard Code
for Information Interchange), and EBCDIC (Extended Binary Coded
Decimal Interchange Code).
★ EBCDIC was developed by IBM. Its use is restricted mostly to IBM and
IBM-compatible mainframe computers and terminals. The Web makes
EBCDIC particularly unsuitable for current work. Nearly everyone
today uses Unicode or ASCII. Still, it will be many years before EBCDIC
totally disappears from the landscape.
Y o u
a nk
Th