SlideShare a Scribd company logo
Computer and Network
Technology (CNT)
Chapter: Fundamentals
Lesson: Data Representation in Computers
Representation of Integers
Lecturer: Susantha Herath PGD in IT (MBCS), PGD in Marketing (Uni. Of Kln)
Lecture 02 bcsonlinelectures.com
Few basic things to know
 Most Significant Bit (MSB) also called as Most Significant Digit (MSD). This is
indeed the first digit (from left) in a binary number. More accurately the digit
with the highest radix (base) value.
 Least Significant Bit (LSB) or Least Significant Digit (LSD). This is the digit of a
binary number with the least radix value, probably the last digit.
 In binary number one digit is called as a bit.
 Computer memory is a place that store data and it has a fixed length of bits.
Generally 8bit, 16bit, 32bit and 64bit in length.
1001100100111
212 (MSD) 20 (LSD)
Data Representation
 Computer uses a fixed number of bits to represent a single piece of data. Generally
computers use 8bit, 16bit, 32bit and 64bit in size of binary numbers to represent
different type and size of data.
 N-number of bit memory (location) can store 2n of different types of values.
 For an example 8bit memory can store 256 of different data values.
 3bit memory can store 8 distinct values (patterns)
000, 001, 010, 011, 100, 101, 110, or 111
 When we interpret these values, we need to know exactly what represent with
these values.
 If we know that these represent decimal numbers, then we know it is from 0-7 then
it is a different value.
 So this interpretation of a binary pattern called data representation or encoding.
Integer Representation
 Integers are whole numbers or fixed point numbers. The radix point is fixed after
the LSB.
Example:
377410 is a fixed point number (integer)
2949.9410 is a floating point number (real number)
54533. 4573.55
LSB Radix Point Fixed
Radix Point Moved from LSB
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.
 There are three schemas (ways) to represent signed integers.
 Sign Magnitude representation
 1’s complement representation
 2’s complement representation
Integer Representation
 We learned about two different types of Integers;
 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.
Example: 8bit binary number 0100 0010B (B = Binary)
0100 0010B = 2x21 + 2x26 = 4+64 = 68D (D = Decimal)
8bit = 0000 0000
16bit = 0000 0000 0000 0000
32bit = 0000 0000 0000 0000 0000 0000 0000 0000
64bit = 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
All above numbers represent zero in different bit systems. The bit length of each system is different.
n-bit Unsigned Integers
 An n-bit pattern can represent 2n distinct integers. This range from 0 to (2n)-1
n-bit Minimum 2n – 1 Maximum
8bit 0 28 – 1 255
16bit 0 216 – 1 65,535
32bit 0 232 – 1 4,294,967,295
64bit 0 264 – 1 18,446,744,073,709,551,615
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 8bit number, selecting 32bit length to store small numbers is a
waste of resources.
Signed Integers
 Signed integers can represent zero, positive and negative numbers.
 The MSB (Most Significant Bit) – Normally the first bit from left, represent the
sign of the integer. Zero (0) to represent positive (+) sign and One (1) to
represent negative (-) sign.
 The magnitude of the integer represent differently in different schemas.
 There are three schemas to represent signed integers.
1. Sign Magnitude Representation
2. 1’s Complement Representation
3. 2’s Complement Representation
Example of Signed Integers:
+2344 is a positive integer -23434 is a negative integer
n-bit Sign Magnitude Representation
 Most Significant Bit (MSB) is the sign bit. 0 representing positive and 1
representing negative signs.
 The remaining (n-1) bits represent the magnitude / absolute value of the
integer interpreted according to its binary pattern.
Examples:
n=8 (8bit number) and binary number is 01000001
Sign bit (MSB) is 0  this is a positive number
Absolute value 1000001  65
01000001B = +65D
B = Binary, D = Decimal
n-bit Sign Magnitude Representation
Examples:
n=8 (8bit number) and binary number is 00000000
Sign bit (MSB) is 0  this is a positive number
Absolute value 0000000  0
00000000B = +0D
n=8 (8bit number) and binary number is 10000000
Sign bit (MSB) is 1  this is a negative number
Absolute value 0000000  0
10000000B = -0D
n-bit Sign Magnitude Representation
Problems (Drawbacks / Limitations) of Sign Magnitude Representation:
 There are two
representation for the
number zero
 Even the number zero
need to have a sign, since
it is not necessary nor
accurate and may leads to
confusions.
 Positive and negative
numbers need to process
separately.
n-bit 1’s Complement Representation
In this representation, the MSB is the sign bit 0 represent positive and 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).
Example: 1 000 0001B (sign bit = 1, negative integer)
Complement of 000 0001 is 111 1110 = 126D
1 000 0001B = -126D
n-bit 1’s Complement Representation
In the 1’s Complement
Representation, there are two
different representation for zero;
0000 0000B and 1111 1111B
hence +0 and -0
Since the processing method of
positive and negative integers
are different, computer need to
process the positive and
negative numbers separately.
n-bit 2’s Complement Representation
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.
Example: 1 000 0001B (MSB = 1 is a negative number)
Complement of 000 0001 = 111 1110
Let’s add 1 to the complement = 111 1111 = 127
1 000 0001B = -127D
n-bit 2’s Complement Representation
Advantages of 2’s Complement
Representation
 There is only one
representation for the number 0
 In binary addition and
subtraction, both positive and
negative numbers can treated
together (process together)
 Subtraction can use the addition
logic
 Computers use 2’s Complement
Representation for processing
integers.
n-bit 2’s Complement Representation
Addition, Subtraction, Overflow and Underflow
Addition of positive integers
Example: n=8, 65D + 5D = 70D
65D  0100 0001B
5D  0000 0101B
65D + 5D  0100 0110B OK 70D within the range of -128 to +127
Subtraction is the addition of positive and negative integers
Example: n=8, 65D – 5D = 60D  65D + (-5D)
65D  0100 0001B
-5D  1111 1011B
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 + D = 129D (not within -128 and +127, exceed
maximum value)
127D  0111 1111B
2D  0000 0010B
127D + 2D  1000 0001B  -127D wrong answer
Example of underflow: n=8, -125D – 5D = -130D (not within -128 and +127, below
the minimum value)
-125D  1000 0011B
-5D  1111 1011B
-125D + (-5D)  0111 1110B  +126D wrong answer
n-bit 2’s Complement Representation
Range of n-bit 2’s complement signed integers
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.
8bit from -128 to +127
16bit from -32,768 to +32,767
32bit from -2,147,483,648 to + 2,147,483,647
64bit from -9,223,372,036,854,775,888 to + 9,223,372,036,854,775,887
n-bit 2’s Complement Representation
decoding 2’s complement numbers
• 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
Big Endian vs. Little Endian
Modern computers store one byte of memory in single memory location / address.
1 byte = 8 bits. Therefore in 32bit integer stores in 4 memory locations.
Term “Endian” means the order of storing bytes in memory. In Big Endian standard
– the most significant byte stores first in the lowest memory location. In Little
Endian standard, the least significant byte (LSB) stores in the lowest memory
location.
Floating Point Number
Representation
A floating point number (also called as a real number) is a number with a decimal
point. A floating point number can represent a very large positive or negative
number as well as a very small negative or positive number. A real number has a
range of -1.23x1088 to 1.25x1088 including zero.
Scientifically a floating point number represent as a number with a fraction and
exponent of a certain radix. F x rE
Floating Point Number
Representation
Same floating point number can represent in different ways. Consider 5.456D
We can represent this number in following ways:
54.532 x 100
5.4532 x 101
0.54532 x 102 and so on….
Since there are many ways to represent the same floating point number, we need
to define a standard, so every floating point number should be in this standard. To
make it standard, we can normalized the fraction part. In normalized form, there is
only single none zero digit represent before the radix point. In above example
5.4532 x 101 is the normalized form of 54.532 number.
Floating Point Number
Representation
In computers, there is an issue of “Loss of Precision” in storing floating point
numbers. An n-bit system can only stores 2n distinct finite numbers. Even within a
small range 0.00 – 0.01, there are infinite number of decimal numbers. But the
number of bits in a computer system is limited, only a the approximate number
used, resulting in loss of accuracy.
Processing of a real number (floating number arithmetic) is very much less efficient
and slower than processing of integers. In computers, real numbers uses fraction
(F) and exponent (E) with radix (r) of 2. Both F and E can be negative or positive.
In modern computing uses IEEE 754 standard to represent floating point numbers.
There are two representation schemes
32 bit single precision and
64 bit double precision
IEEE-754 32-bit Single-Precision
Floating-Point Numbers
In 32-bit single precision floating point number representation, decimal number
represent in following structure:
• The most significant bit is the sign bit. Zero for positive numbers and One for
negative numbers.
• Next following 8bit represent the exponent (E)
• Remaining 23bit represent the fraction (F)
You may wonder why radix (r) is not represent here. Because radix is always 2 for
binary numbers (in computers).
IEEE-754 64-bit Double-Precision
Floating-Point Numbers
64-bit double precision floating point number representation is similar to 32-bit
single precision floating point number representation. Only difference is assignment
of bit range for exponent and fraction.
• The most significant bit is the sign bit. Zero for positive numbers and One for
negative numbers.
• Next following 11-bit represent the exponent (E)
• Remaining 52-bit represent the fraction (F)
Character Encoding
In computer memory, characters are represented (encode) using character
schemes called as “character set”, “charset”, “character map” or “code page”.
There are several standard schemes such as ASCII, EBCDIC, UTF, etc.
7-bit ASCII Code (aka US-ASCII, ISO/IEC 646, ITU-T T.50)
• ASCII (American Standard Code for Information Interchange) is one of the earlier
character coding schemes.
• ASCII is originally a 7-bit code. It has been extended to 8-bit to better utilize the 8-bit
computer memory organization. (The 8th-bit was originally used for parity check in
the early computers). This is called ASCII-8 Code.
EBCDIC Code
This is stands for “Extended Binary Code Decimal Interchange Code”. This is a 8-bit
code scheme without parity. With this up to 256 characters can be coded.
Character Encoding
Unicode (aka ISO/IEC 10646 Universal Character Set)
• Before Unicode, no single character encoding scheme could represent characters in
all languages.
• Unicode aims to provide a standard character encoding scheme, which is universal,
efficient, uniform and unambiguous. Unicode standard is maintained by a non-profit
organization called the Unicode Consortium (@ www.unicode.org). Unicode is an
ISO/IEC standard 10646.
• Unicode is backward compatible with the 7-bit US-ASCII and 8-bit Latin-1 (ISO-8859-
1). That is, the first 128 characters are the same as US-ASCII; and the first 256
characters are the same as Latin-1.
• Unicode originally uses 16 bits , which can represent up to 65,536 characters.
Summary
Inside the computer memory – integer 1, floating point 1.0, character 1 and string 1
are totally different. To write good and high performance programs, you need to
know these differences and use correct data type to store data in memory and later
on in databases as well.
• In 8-bit signed integer, integer number 1 is represented as 00000001B.
• In 8-bit unsigned integer, integer number 1 is represented as 00000001B.
• In 16-bit signed integer, integer number 1 is represented as 00000000 00000001B.
• In 32-bit signed integer, integer number 1 is represented
as 00000000 00000000 00000000 00000001B.
• In 32-bit floating-point representation, number 1.0 is represented as 0 01111111
0000000 00000000 00000000B, i.e., S=0, E=127, F=0.
• In 64-bit floating-point representation, number 1.0 is represented as 0 01111111111 0000
00000000 00000000 00000000 00000000 00000000 00000000B,
i.e., S=0, E=1023, F=0.
End of Lesson
www.bcsonlinelectures.com

More Related Content

PPTX
Binary Arithmetic
PPT
Number system and codes
PPTX
PPT
BOOLEAN ALGEBRA
PPTX
Binary addition.pptx
PPTX
Binary arithmetic
PDF
Number System and Boolean Algebra
PPT
Complements
Binary Arithmetic
Number system and codes
BOOLEAN ALGEBRA
Binary addition.pptx
Binary arithmetic
Number System and Boolean Algebra
Complements

What's hot (20)

PPTX
Quick tutorial on IEEE 754 FLOATING POINT representation
PPTX
Floating point representation
PPT
Addition and subtraction with signed magnitude data (mano
PPTX
Number system in Digital Electronics
PDF
Instruction code
PPSX
Algorithm and flowchart
PDF
Digital Electronics- Number systems & codes
PPTX
Chapter 03 arithmetic for computers
PPTX
Computer Organization
PPTX
Number system conversion
PPTX
Microoperations
PPTX
Booths algorithm for Multiplication
PPTX
Number system....
PDF
Binaty Arithmetic and Binary coding schemes
DOCX
Number system.pdf
PPTX
Unit 4-booth algorithm
PPT
Integer Representation
PPTX
Computer architecture addressing modes and formats
PPTX
Computer architecture data representation
Quick tutorial on IEEE 754 FLOATING POINT representation
Floating point representation
Addition and subtraction with signed magnitude data (mano
Number system in Digital Electronics
Instruction code
Algorithm and flowchart
Digital Electronics- Number systems & codes
Chapter 03 arithmetic for computers
Computer Organization
Number system conversion
Microoperations
Booths algorithm for Multiplication
Number system....
Binaty Arithmetic and Binary coding schemes
Number system.pdf
Unit 4-booth algorithm
Integer Representation
Computer architecture addressing modes and formats
Computer architecture data representation
Ad

Similar to Representation of Integers (20)

PDF
DigitalLogic_NumberRepresentation.pdf advanced
PPTX
1 number systems-unsignedsignedintegers
PDF
Data representation computer architecture
PPTX
Lecture 1
DOCX
Data representation
PPT
Chapter 02 Data Types
PDF
Unit 1 - Introduction to Digital Computer (computer organization.pdf
PPT
Data Representation in Information Technology
PPTX
DE -gxgxhxydydydfyfduffuf UEEB02 - L 7.pptx
PDF
NumberSystemsAnnotated.pdf
PPTX
Unit I-L1 - Basics of Digital Computer Organization and Architecture
PPTX
Data Representation
PPT
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
PPT
Data storage (number,string,sound, image and video
PPTX
Unsigned and Signed fixed point Addition and subtraction
PPTX
Lecture 7 Data Representation (1).pptx for computer organization and architec...
PPT
3.Fixed-Floating Point.ppt
PPT
Counit2
PDF
Csc1401 lecture03 - computer arithmetic - arithmetic and logic unit (alu)
PDF
Notes unit 2
DigitalLogic_NumberRepresentation.pdf advanced
1 number systems-unsignedsignedintegers
Data representation computer architecture
Lecture 1
Data representation
Chapter 02 Data Types
Unit 1 - Introduction to Digital Computer (computer organization.pdf
Data Representation in Information Technology
DE -gxgxhxydydydfyfduffuf UEEB02 - L 7.pptx
NumberSystemsAnnotated.pdf
Unit I-L1 - Basics of Digital Computer Organization and Architecture
Data Representation
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Data storage (number,string,sound, image and video
Unsigned and Signed fixed point Addition and subtraction
Lecture 7 Data Representation (1).pptx for computer organization and architec...
3.Fixed-Floating Point.ppt
Counit2
Csc1401 lecture03 - computer arithmetic - arithmetic and logic unit (alu)
Notes unit 2
Ad

Recently uploaded (20)

PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
Introduction to pro and eukaryotes and differences.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Computer Architecture Input Output Memory.pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
Computing-Curriculum for Schools in Ghana
B.Sc. DS Unit 2 Software Engineering.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Introduction to pro and eukaryotes and differences.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
Paper A Mock Exam 9_ Attempt review.pdf.
Computer Architecture Input Output Memory.pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Weekly quiz Compilation Jan -July 25.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf

Representation of Integers

  • 1. Computer and Network Technology (CNT) Chapter: Fundamentals Lesson: Data Representation in Computers Representation of Integers Lecturer: Susantha Herath PGD in IT (MBCS), PGD in Marketing (Uni. Of Kln) Lecture 02 bcsonlinelectures.com
  • 2. Few basic things to know  Most Significant Bit (MSB) also called as Most Significant Digit (MSD). This is indeed the first digit (from left) in a binary number. More accurately the digit with the highest radix (base) value.  Least Significant Bit (LSB) or Least Significant Digit (LSD). This is the digit of a binary number with the least radix value, probably the last digit.  In binary number one digit is called as a bit.  Computer memory is a place that store data and it has a fixed length of bits. Generally 8bit, 16bit, 32bit and 64bit in length. 1001100100111 212 (MSD) 20 (LSD)
  • 3. Data Representation  Computer uses a fixed number of bits to represent a single piece of data. Generally computers use 8bit, 16bit, 32bit and 64bit in size of binary numbers to represent different type and size of data.  N-number of bit memory (location) can store 2n of different types of values.  For an example 8bit memory can store 256 of different data values.  3bit memory can store 8 distinct values (patterns) 000, 001, 010, 011, 100, 101, 110, or 111  When we interpret these values, we need to know exactly what represent with these values.  If we know that these represent decimal numbers, then we know it is from 0-7 then it is a different value.  So this interpretation of a binary pattern called data representation or encoding.
  • 4. Integer Representation  Integers are whole numbers or fixed point numbers. The radix point is fixed after the LSB. Example: 377410 is a fixed point number (integer) 2949.9410 is a floating point number (real number) 54533. 4573.55 LSB Radix Point Fixed Radix Point Moved from LSB
  • 5. 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.  There are three schemas (ways) to represent signed integers.  Sign Magnitude representation  1’s complement representation  2’s complement representation
  • 6. Integer Representation  We learned about two different types of Integers;  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. Example: 8bit binary number 0100 0010B (B = Binary) 0100 0010B = 2x21 + 2x26 = 4+64 = 68D (D = Decimal) 8bit = 0000 0000 16bit = 0000 0000 0000 0000 32bit = 0000 0000 0000 0000 0000 0000 0000 0000 64bit = 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 All above numbers represent zero in different bit systems. The bit length of each system is different.
  • 7. n-bit Unsigned Integers  An n-bit pattern can represent 2n distinct integers. This range from 0 to (2n)-1 n-bit Minimum 2n – 1 Maximum 8bit 0 28 – 1 255 16bit 0 216 – 1 65,535 32bit 0 232 – 1 4,294,967,295 64bit 0 264 – 1 18,446,744,073,709,551,615 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 8bit number, selecting 32bit length to store small numbers is a waste of resources.
  • 8. Signed Integers  Signed integers can represent zero, positive and negative numbers.  The MSB (Most Significant Bit) – Normally the first bit from left, represent the sign of the integer. Zero (0) to represent positive (+) sign and One (1) to represent negative (-) sign.  The magnitude of the integer represent differently in different schemas.  There are three schemas to represent signed integers. 1. Sign Magnitude Representation 2. 1’s Complement Representation 3. 2’s Complement Representation Example of Signed Integers: +2344 is a positive integer -23434 is a negative integer
  • 9. n-bit Sign Magnitude Representation  Most Significant Bit (MSB) is the sign bit. 0 representing positive and 1 representing negative signs.  The remaining (n-1) bits represent the magnitude / absolute value of the integer interpreted according to its binary pattern. Examples: n=8 (8bit number) and binary number is 01000001 Sign bit (MSB) is 0  this is a positive number Absolute value 1000001  65 01000001B = +65D B = Binary, D = Decimal
  • 10. n-bit Sign Magnitude Representation Examples: n=8 (8bit number) and binary number is 00000000 Sign bit (MSB) is 0  this is a positive number Absolute value 0000000  0 00000000B = +0D n=8 (8bit number) and binary number is 10000000 Sign bit (MSB) is 1  this is a negative number Absolute value 0000000  0 10000000B = -0D
  • 11. n-bit Sign Magnitude Representation Problems (Drawbacks / Limitations) of Sign Magnitude Representation:  There are two representation for the number zero  Even the number zero need to have a sign, since it is not necessary nor accurate and may leads to confusions.  Positive and negative numbers need to process separately.
  • 12. n-bit 1’s Complement Representation In this representation, the MSB is the sign bit 0 represent positive and 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). Example: 1 000 0001B (sign bit = 1, negative integer) Complement of 000 0001 is 111 1110 = 126D 1 000 0001B = -126D
  • 13. n-bit 1’s Complement Representation In the 1’s Complement Representation, there are two different representation for zero; 0000 0000B and 1111 1111B hence +0 and -0 Since the processing method of positive and negative integers are different, computer need to process the positive and negative numbers separately.
  • 14. n-bit 2’s Complement Representation 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. Example: 1 000 0001B (MSB = 1 is a negative number) Complement of 000 0001 = 111 1110 Let’s add 1 to the complement = 111 1111 = 127 1 000 0001B = -127D
  • 15. n-bit 2’s Complement Representation Advantages of 2’s Complement Representation  There is only one representation for the number 0  In binary addition and subtraction, both positive and negative numbers can treated together (process together)  Subtraction can use the addition logic  Computers use 2’s Complement Representation for processing integers.
  • 16. n-bit 2’s Complement Representation Addition, Subtraction, Overflow and Underflow Addition of positive integers Example: n=8, 65D + 5D = 70D 65D  0100 0001B 5D  0000 0101B 65D + 5D  0100 0110B OK 70D within the range of -128 to +127 Subtraction is the addition of positive and negative integers Example: n=8, 65D – 5D = 60D  65D + (-5D) 65D  0100 0001B -5D  1111 1011B 65D + (-5D)  0011 1100B  60D OK within the range of -128 to +127
  • 17. 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 + D = 129D (not within -128 and +127, exceed maximum value) 127D  0111 1111B 2D  0000 0010B 127D + 2D  1000 0001B  -127D wrong answer Example of underflow: n=8, -125D – 5D = -130D (not within -128 and +127, below the minimum value) -125D  1000 0011B -5D  1111 1011B -125D + (-5D)  0111 1110B  +126D wrong answer
  • 18. n-bit 2’s Complement Representation Range of n-bit 2’s complement signed integers 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. 8bit from -128 to +127 16bit from -32,768 to +32,767 32bit from -2,147,483,648 to + 2,147,483,647 64bit from -9,223,372,036,854,775,888 to + 9,223,372,036,854,775,887
  • 19. n-bit 2’s Complement Representation decoding 2’s complement numbers • 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
  • 20. Big Endian vs. Little Endian Modern computers store one byte of memory in single memory location / address. 1 byte = 8 bits. Therefore in 32bit integer stores in 4 memory locations. Term “Endian” means the order of storing bytes in memory. In Big Endian standard – the most significant byte stores first in the lowest memory location. In Little Endian standard, the least significant byte (LSB) stores in the lowest memory location.
  • 21. Floating Point Number Representation A floating point number (also called as a real number) is a number with a decimal point. A floating point number can represent a very large positive or negative number as well as a very small negative or positive number. A real number has a range of -1.23x1088 to 1.25x1088 including zero. Scientifically a floating point number represent as a number with a fraction and exponent of a certain radix. F x rE
  • 22. Floating Point Number Representation Same floating point number can represent in different ways. Consider 5.456D We can represent this number in following ways: 54.532 x 100 5.4532 x 101 0.54532 x 102 and so on…. Since there are many ways to represent the same floating point number, we need to define a standard, so every floating point number should be in this standard. To make it standard, we can normalized the fraction part. In normalized form, there is only single none zero digit represent before the radix point. In above example 5.4532 x 101 is the normalized form of 54.532 number.
  • 23. Floating Point Number Representation In computers, there is an issue of “Loss of Precision” in storing floating point numbers. An n-bit system can only stores 2n distinct finite numbers. Even within a small range 0.00 – 0.01, there are infinite number of decimal numbers. But the number of bits in a computer system is limited, only a the approximate number used, resulting in loss of accuracy. Processing of a real number (floating number arithmetic) is very much less efficient and slower than processing of integers. In computers, real numbers uses fraction (F) and exponent (E) with radix (r) of 2. Both F and E can be negative or positive. In modern computing uses IEEE 754 standard to represent floating point numbers. There are two representation schemes 32 bit single precision and 64 bit double precision
  • 24. IEEE-754 32-bit Single-Precision Floating-Point Numbers In 32-bit single precision floating point number representation, decimal number represent in following structure: • The most significant bit is the sign bit. Zero for positive numbers and One for negative numbers. • Next following 8bit represent the exponent (E) • Remaining 23bit represent the fraction (F) You may wonder why radix (r) is not represent here. Because radix is always 2 for binary numbers (in computers).
  • 25. IEEE-754 64-bit Double-Precision Floating-Point Numbers 64-bit double precision floating point number representation is similar to 32-bit single precision floating point number representation. Only difference is assignment of bit range for exponent and fraction. • The most significant bit is the sign bit. Zero for positive numbers and One for negative numbers. • Next following 11-bit represent the exponent (E) • Remaining 52-bit represent the fraction (F)
  • 26. Character Encoding In computer memory, characters are represented (encode) using character schemes called as “character set”, “charset”, “character map” or “code page”. There are several standard schemes such as ASCII, EBCDIC, UTF, etc. 7-bit ASCII Code (aka US-ASCII, ISO/IEC 646, ITU-T T.50) • ASCII (American Standard Code for Information Interchange) is one of the earlier character coding schemes. • ASCII is originally a 7-bit code. It has been extended to 8-bit to better utilize the 8-bit computer memory organization. (The 8th-bit was originally used for parity check in the early computers). This is called ASCII-8 Code. EBCDIC Code This is stands for “Extended Binary Code Decimal Interchange Code”. This is a 8-bit code scheme without parity. With this up to 256 characters can be coded.
  • 27. Character Encoding Unicode (aka ISO/IEC 10646 Universal Character Set) • Before Unicode, no single character encoding scheme could represent characters in all languages. • Unicode aims to provide a standard character encoding scheme, which is universal, efficient, uniform and unambiguous. Unicode standard is maintained by a non-profit organization called the Unicode Consortium (@ www.unicode.org). Unicode is an ISO/IEC standard 10646. • Unicode is backward compatible with the 7-bit US-ASCII and 8-bit Latin-1 (ISO-8859- 1). That is, the first 128 characters are the same as US-ASCII; and the first 256 characters are the same as Latin-1. • Unicode originally uses 16 bits , which can represent up to 65,536 characters.
  • 28. Summary Inside the computer memory – integer 1, floating point 1.0, character 1 and string 1 are totally different. To write good and high performance programs, you need to know these differences and use correct data type to store data in memory and later on in databases as well. • In 8-bit signed integer, integer number 1 is represented as 00000001B. • In 8-bit unsigned integer, integer number 1 is represented as 00000001B. • In 16-bit signed integer, integer number 1 is represented as 00000000 00000001B. • In 32-bit signed integer, integer number 1 is represented as 00000000 00000000 00000000 00000001B. • In 32-bit floating-point representation, number 1.0 is represented as 0 01111111 0000000 00000000 00000000B, i.e., S=0, E=127, F=0. • In 64-bit floating-point representation, number 1.0 is represented as 0 01111111111 0000 00000000 00000000 00000000 00000000 00000000 00000000B, i.e., S=0, E=1023, F=0.