Chapter 1 Representing Data in a Computer Main contents Common
ways that representing data in microcomputer. number character
Slide 2
Aims Introduce common ways that representing data in computer
Binary numbers Hexadecimal Numbers ASCII codes for characters
(ASCII BCD codes Calculation of Binary Change between Binary and
Hexadecimal
Slide 3
Outcomes 1. Can convert among binary, decimal, and hexadecimal
numbers. 2. Can differentiate and represent numeric and alphabetic
information as integers, BCD, and ASCII data.
Slide 4
1.1 Binary and Hexadecimal Numbers Binary numbering System
Hexadecimal numbering System Octal numbering System Conversion of
Integer between Binary, Hexadecimal and Decimal
Slide 5
Decimal Number Being used in our life Base 10 Example:
36864=310 4 +6 10 3 +8 10 2 +6 10 1 +4 10 0
Slide 6
Binary Number Being used in computer Represent data in bits
Binary digits, zero(0)/one(1) Base 2 Example: 1101b=1*2 3 +1*2 2
+0*2 1 +1*2 0
Slide 7
Conversion between Binary Number and Decimal Number Convert
from Decimal To Binary Divide DecimalNumber by 2(base of
Binary),getting Quotient and Remainder Remainder is the next
digit(right to left); Example 5876 Convert from Binary to Decimal
Multiply each bit by powers of 2 Example 1101110101b
Slide 8
Hexadecimal Number Binary Number is difficult to be read and
write Hexadecimal Number is a convenient representation of binary
numbers Base 16 0~9,A,B,C,D,E,F Example 3B8E2H
Slide 9
Conversion between Hexadecimal Number and Decimal Number
Convert from Decimal To Hexadecimal Example:5876 Divide
DecimalNumber by 16(base of hexadecimal), getting Quotient and
Remainder Remainder is the next digit(right to left); Convert from
hexadecimal to Decimal Example:8EFh Multiply each bit by powers of
16
Slide 10
Conversion between Hexadecimal Number and Binary Number Convert
from Hexadecimal To Binary Substitute four bits for each hex digit
Pading with leading zeros as needed E.g. 8EFh Convert from Binary
to Hexadecimal From the right, breaking the binary number into
groups of four bits Substitute the corresponding hex digit for each
group of four bits E.g. 100b
Slide 11
Octal Number Base 8 0~7 Example 123O
Slide 12
Conversion between binary and Octal Convert from Octal To
Binary Substitute three bits for each octal digit Pading with
leading zeros as needed E.g. 123o Convert from Binary to Octal From
the right, breaking the binary number into groups of three bits
Substitute the corresponding octal digit for each group of three
bits E.g. 1011011b
Slide 13
1.2 Character Codes Character---Letters, numeral, punctuation
marks and so on Assigning a numeric value to each character
American Standard Code for Information Interchange(ASCII) is
commonly used
Slide 14
ASCII Seven bits to represent characters, so 128 different
characters can be represented using ASCII codes. Printable
characters: 20h~7eh A~Z 41h~5ah a~z 61h~7ah 0~9 30h~39h Control
characters:00h~1fh ESC 1bh, 0dh carriage return(CR ), 0AH line
feed(LF )
Slide 15
Computer Data Formats: BCD BCD digit 0000 ~ 1001 binary ( 0000
2 ~ 1001 2 ) 0 ~ 9 decimal Two forms Packed BCD ( ): two digits per
byte Unpacked BCD ( ): one digit per byte Decimalpacked BCDunpacked
BCDHex 120001 00100000 0001 0000 00100CH 961001 01100000 1001 0000
011060H 96H 0906H
Slide 16
1.3 2s Complement Representation for Signed Integers To form a
twos complement Method one: Invert each bit of a number from 0 to 1
or from 1 to 0, then add a 1 Method two: Subtract the number by 0
+8 =00001000 11110111 + 1 -8 =11111000 0 =100000000 -(8=00001000)
-8 =11111000
Slide 17
Byte-Sized Data One byte, 8 bits, 00H~FFH Unsigned integer ( ):
0 ~ 255 signed integer ( ): -128 ~ 0 ~ +127 Negative signed numbers
are stored in the twos complement form ( ) To store 8-bit data, use
DB directive
Slide 18
Word-Sized Data Two bytes, 16 bits, 0000H~FFFFH Unsigned
integer : 0 ~ 65,535 ( 2 16 -1) signed integer : -32,768 ~ 0 ~
+32767 13400 = 3458H, 0 - 3458H = CBA8H So, -13400 = CBA8H in twos
complement Please note -1 = FFFFH (word-sized ) in twos complement
-1 = FFH (byte-sized ) in twos complement
Slide 19
Data type ( Byte: 8bits Word:16bits Doubleword:32bits
Quaword:64bits
Slide 20
1.4 Addition and subtraction of 2s complement numbers Discusses
addition and subtraction of 2s complement numbers Introduces the
concepts of carry and overflow
Slide 21
Addition of hex numbers 0 A 0 7 + 0 1 D 3 0 B D A 7+3=10=A
0+D=0+13=13=D A+1=10+1=11=B 0+0=B 2567 + 467 3034 BDAh=3034d
Slide 22
Addition of hex numbers 0206 + FFB0 101B6 0+6=6 0+B=0+12=12=B
2+F=2+15=17=1+16(carry) 0+F+1(carry)=16=1+16(carry) signed number:
518+(-80)=438 unsigned number: 518+65456=65974 101B6h=65974(can t
be represented in a word) 01B6h=438 carr y
Slide 23
Addition of hex numbers FFE7 + FFF6 1FFDD 7+6=13=D
E+F=14+15=29=16 (carry) +13=D F+F=15+15+1 (carry)
=31=15+16(carry)=F F+F+1(carry)=31=15+16(carry)=F signed number:
(-25)+(-10)=-35 unsigned number: 65511+65526=131037
1FFDDh=131037(can t be represented in a word) FFDDh=-35 carr y
Slide 24
Addition of hex numbers 483F + 645A AC99 18495+25690=44185
signed number: AC99H=-21351 unsigned number: AC99h=44185
Slide 25
Addition of hex numbers E9FF + 8CF0 176EF 76EFH=30447 signed
number: (-5633)+(-29456)=-35089 unsigned number: 59903+36080=95983
carry
Slide 26
CARRY AND OVERFLOW Carry into sign bit? Carry out of sign bit?
Overflow? no yes noyes no
Subtraction of hex numbers In a computer, subtraction a-b of
numbers a and b is usually performed by taking the 2s complement of
b and adding the result to a. That means adding the negation of
b.
Slide 29
0 0 C 3 - 0 2 6 A 0 0 C 3 + F D 9 6 F E 5 9 If there is no
carry in the addition, then there is a borrow in the subtraction.
195 618 423 FE59H=-423
Slide 30
0 3 D 9 - 0 1 9 B 0 3 D 9 + F E 6 5 1 0 2 3 E If there is a
carry in the addition, then there is no borrow in the subtraction.
985 411 574 023EH=574
Slide 31
8 E 3 D - 3 C 5 7 8 E 3 D + C 3 A 9 1 5 1 E 6 If overflow
occurs in the addition, then it occurs in the original subtraction
problem;if it does not occur in the addition, then it does not
occur in the original subtraction. -29123 15447 - 44570 (outside
the range)
Slide 32
Can you summarize another regulation of carry or overflow
occurring?
Slide 33
1.5 Other Systems for Representing Numbers 1s complement Binary
Coded Decimal BCD Floating point
Slide 34
Computerese Computerese, Computer terminology Terms and jargon
used in the computer field Technical terms For example, He spoke
such a jargon, I couldnt make head or tail of what he said.
Return
Slide 35
Computerese-1 Numerica. Alphabetica. Alphanumerica. Data type
integer floating-point BCD (Binary-coded decimal) ASCII (American
Standard Code for Information Interchange)
Slide 36
Computerese-2 bit (binary digit) Byte = 8 bits Word = 2 bytes
(16-bit) Double word = 2 words (32-bit) Quad word = 4 words
(64-bit) 4 Binary Decimal Hexadecimal