0% found this document useful (0 votes)
21 views

Lecture#11#12_CSE_1012(4)

Uploaded by

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

Lecture#11#12_CSE_1012(4)

Uploaded by

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

Lecture # 11&12

CSE-1010 :Programming I

Transforming Education. Enriching Lives

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 1


Lecture 11

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 2


What will cover today?
• Two’s Complements and overflow in number system

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 3


What is two’s complement?
• Two’s complement is a method
that helps to encode negative
numbers in computers.
• Since positive numbers are
represented in the form of
normal binary numbers, they do
not needspecialrepresentation.
• Most computers use two’s
complement to store signed
numbers.
https://www.allmath.com/blogs/what-is-twos-
complement#:~:text=Well%2C%20the%20answer%20is
%20for%20the%20sake%20of,adding%20two%20opposite
%20signed%20numbers%20requires%20different
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 4
%20algorithms.
• Computer Architecture
• 2’s Complement Number System is widely used.
• overflow here mainly will we with respect to 2’s Complimentary System.
• N-bit 2’s Complement number System can represent Number
• from - 2^{n-1} to 2^{n-1} -1
• 4 Bit can represent numbers from ( -8 to 7 )
• 5 Bit can represent numbers from ( -16 to 15 ) in 2’s Complimentary System.
• Overflow Occurs with respect to addition when 2 N-bit 2’s Complement Numbers are added
and the answer is too large to fit into that N-bit Group.
• A computer has N-Bit Fixed registers.
• Addition of two N-Bit Number will result in a max N+1 Bit number.
• That Extra Bit is stored in carry Flag.
• But Carry does not always indicate overflow.
• In the 8-bit system, we need to check whether overflow occurs for the given operations.
Overflow happens when the result of an addition goes beyond the range representable by the
signed 8-bit system, which is −128 to 127..
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 5
Overflow Detection –
Overflow occurs when:
Two negative numbers are added and an answer comes positive or
Two positive numbers are added and an answer comes as negative.
So overflow can be detected by checking Most Significant Bit(MSB) of
two operands and answer.

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 6


8+ 9 in 8 bit system 00001000+00001001=0001001 carry1
positive+ positive=positive
Sum: 00001000+00001001==00010001 (binary), which is 17 in decimal.
No overflow because the result (17) is within the representable range −128 to 127.
(-8)+(-9) in 8bit system 11111000+11110111=1110111
negative+negative=negative
Sum=−17 in decimal (2's complement).
(-101)+(-29) =10011011+11100011=01111100 carry 1
negative+negative=positive
Sum=124 in decimal (2's complement). Overflow

Negative+negantive= positive
(-101)+(-27)=10011011+11100101=10000000 carry1
negative+negative=negative
Sum=-128 in decimal (2's complement). No overflow
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 7
Overflow can also be detected using 2 Bit
Comparator just by checking Carry-in(C-in)
and Carry-Out(C-out) from MSB’s.

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 8


sum 10000000 in binary represents −128 in decimal due to signed 8-bit representation.

This is incorrect for 127+1, which should be 128(out of range).Overflow occurred.

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 9


01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 10
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 11
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 12
• Overflow Occurs when C-in not equal to C-out. Above expression for
overflow can be explained from below Analysis.

In first Figure the MSB of two numbers are 0 which means they are positive.
Here if C-in is 1 we get answer’s MSB as 1 means answer is negative (Overflow) and C-out as 0.
C-in not equal C-out hence overflow.
In second Figure the MSB of two numbers are 1 which means they are negative.
Input Output
Here if C-in is 0 we get answer MSB as 0 means answer is positive(Overflow) and C-out as 1.
C-in not equal C-out hence overflow. A B A XOR B
Carry-in and Carry-out at MSB’s are enough to detect Overflow. 0 0 0
0 1 1
1 0 1
1 1 0
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 13
Refenceres

Online content
https://www.geeksforgeeks.org/overflow-in-arithmetic-addition-in-
binary-number-system/

• https://www.electronics-tutorials.ws/binary/signed-binary-
numbers.html

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 14


Lecture 12

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 15


-What will cover today
What is ASCII and Unicode in computer science?

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 16


ASCII Code
• American Standard Code for Information Interchange---ASCII
• a character encoding standard for electronic communication
• ASCII codes represent text in computers, telecommunications
equipment, and other devices.
• Most modern character-encoding schemes are based on ASCII,
although they support many additional characters.

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 17


ASCII Code
• 7 bits character code-
can store 128 different characters[7 bit code support 20 to 26
(1+2+4+8+16+32+64=128) combinations]
• Introduced by American National Standard Institute(ANSI)
• Used by personal computer and workstations computer

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 18


ASCII code
• ASCII is often called US-ASCII. Now, ISO 646 is the internationally
defined character sets standard.
• ASCII started a 7-bit code, with 128 characters.
• consists of 33 non-printable and 95 printable characters.
• includes letters, punctuation marks, numbers and control characters.
• later expanded by IBM to an 8-bit code and 256

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 19


ASCII Table

https://smartwebworker.com/ascii-codes/
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 20
21
CSE 1010 (Programming I) - MIIT
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 22
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 23
Extended Binary Coded Decimal
Interchange Code
• Extended binary coded decimal interchange code(EBCDIC)
• 8 bits character encoding techniques
• 28 supports 256 combination of different character
• Used on IBM mainframe operating system.
• EBCDIC is easier to use on punched cards.
• Similar to ASCII characters

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 24


Extended Character

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 25


01/24/2025 https://www.youtube.com/watch?v=B1Sf1IhA0j4 https://www.youtube.com/watch?v=H4l42nbYmrU
MIIT, Mandalay, CSE-1010 Programming I 26
Unicode
• Unicode is a worldwide character-encoding standard, published by the Unicode Consortium. Computers store numbers that represent
a character; Unicode provides a unique number for every character.
• Started created their own encoding scheme for other language characters
• Unicode represents character as integers.
• It has several character encoding scheme
• UTF-8 : use only eight bits to encode English characters
• Widely used in email and internet
• UTF-16: use sixteen bits to encode English characters
• Can represent 65000 characters
• UTF-8 to UTF-16 and UTF-16 to UTF-8 are OK.
• UTF-32 : use 32 bits to encode English characters
• can represent 100,000 characters
• UTF reserves some code for private use, which hardware and software vendors can assign internally for their own characters and
symbols
• Widely used to represent text for computer processing
• Provide multilingual characters-Unicode represents a mechanism to support more regionally popular encoding systems - such as the
ISO-8859 variants in Europe, Shift-JIS in Japan, or BIG-5 in China.
• It is platform, program, and language independent.
• https://www.youtube.com/watch?v=-oYfv794R9s
• https://www.mmunicode.org/myanmar-unicode/
• https://unicode-table.com/en/#greek-extended
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 27
UCS-* and UTF-*

• The two most common encoding schemes store Unicode text as sequences of
either 2 or 4 bytes. The official terms for these encodings are UCS-2 and UCS-4,
respectively.
• UCS stands for Universal Character Set as specified by ISO/IEC 10646.
• The number indicates the number of octets (an octet is 8 bits) in the coded
character set. UCS-2 indicates two octets, while UCS-4 indicates four octets.
• UTF stands for Unicode Transformation Format.
• In order to be compatible with older systems that didn't support Unicode,
Encoding Forms were defined by the Unicode Consortium to be a representation
of the character in bits.
• The number indicates the encoding form that is to be used: UTF-8 indicates an 8-
bit encoding form, while UTF-16 indicates a 16-bit encoding form.
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 28
References
Online Content
Images and Photos are credit to original uploader in Google
https://www.youtube.com/watch?v=B1Sf1IhA0j4
https://www.youtube.com/watch?v=-oYfv794R9s
https://www.youtube.com/watch?v=B1Sf1IhA0j4
• Subramanian, K. R. V., & Subramanian, U. , “ Introductory problem solving and
programming (using C). “Courseware prepared especially for Myanmar Institute
of Information Technology, Mandalay, 2017
• Reema Thareja, “Fundamentals Of Computers”, Oxford University Press, 2015
• Reema Thareja, “Introduction to C Programming”, Second Edition, Oxford
University Press, 2015
01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 29
Learning to write programs stretches your mind, and helps you think
better, creates a way of thinking about things that I think is helpful in
all domains.”

—Bill Gates, Co-Chairman, Bill & Melinda Gates Foundation, Co-Founder, Microsoft

01/24/2025 MIIT, Mandalay, CSE-1010 Programming I 30

You might also like