1. Trang chủ
  2. » Công Nghệ Thông Tin

Chapter03 0datarepresentation

39 0 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 39
Dung lượng 1,02 MB

Nội dung

dce 2015 COMPUTER ARCHITECTURE CSE Fall 2014 Faculty of Computer Science and Engineering Department of Computer Engineering BK TP.HCM Vo Tan Phuong http://www.cse.hcmut.edu.vn/~vtphuong dce 2015 Chapter Data Representation Computer Architecture – Chapter © Spring 2015, CE dce 2015 Presentation Outline • • • • • • • • Positional Number Systems Binary and Hexadecimal Numbers Base Conversions Binary and Hexadecimal Addition Binary and Hexadecimal subtraction Carry and Overflow Character Storage Floating Point Number Computer Architecture – Chapter © Spring 2015, CE dce 2015 Positional Number Systems Different Representations of Natural Numbers XXVII 27 110112 Roman numerals (not positional) Radix-10 or decimal number (positional) Radix-2 or binary number (also positional) Fixed-radix positional representation with k digits Number N in radix r = (dk–1dk–2 d1d0)r Value = dk–1×r k–1 + dk–2×r k–2 + … + d1×r + d0 Examples: (11011)2 = 1×24 + 1×23 + 0×22 + 1×2 + = 27 (2103)4 = 2×43 + 1×42 + 0×4 + = 147 Computer Architecture – Chapter © Spring 2015, CE dce 2015 Binary Numbers • Each binary digit (called bit) is either or • Bits have no inherent meaning, can represent – Unsigned and signed integers – Characters – Floating-point numbers – Images, sound, etc • Bit Numbering Most Significant Bit Least Significant Bit 1 0 1 1 27 26 25 24 23 22 21 20 – Least significant bit (LSB) is rightmost (bit 0) – Most significant bit (MSB) is leftmost (bit in an 8-bit number) Computer Architecture – Chapter © Spring 2015, CE dce Converting Binary to Decimal 2015 • Each bit represents a power of • Every binary number is a sum of powers of • Decimal Value = (dn-1  2n-1) + + (d1  21) + (d0  20) • Binary (10011101)2 = 27 + 24 + 23 + 22 + = 157 1 0 1 1 27 26 25 24 23 22 21 20 Some common powers of Computer Architecture – Chapter © Spring 2015, CE dce 2015 Convert Unsigned Decimal to Binary • Repeatedly divide the decimal integer by • Each remainder is a binary digit in the translated value least significant bit 37 = (100101)2 most significant bit stop when quotient is zero Computer Architecture – Chapter © Spring 2015, CE dce 2015 Hexadecimal Integers • 16 Hexadecimal Digits: – 9, A – F • More convenient to use than binary numbers Binary, Decimal, and Hexadecimal Equivalents Computer Architecture – Chapter © Spring 2015, CE dce 2015 Converting Binary to Hexadecimal  Each hexadecimal digit corresponds to binary bits  Example: Convert the 32-bit binary number to hexadecimal 1110 1011 0001 0110 1010 0111 1001 0100  Solution: E 1110 B 1011 0001 0110 Computer Architecture – Chapter A 1010 0111 1001 0100 © Spring 2015, CE dce 2015 Converting Hexadecimal to Decimal • Multiply each digit by its corresponding power of 16 Value = (dn-1  16n-1) + (dn-2  16n-2) + + (d1  16) + d0 • Examples: (1234)16 = (1  163) + (2  162) + (3  16) + = Decimal Value 4660 (3BA4)16 = (3  163) + (11  162) + (10  16) + = Decimal Value 15268 Computer Architecture – Chapter © Spring 2015, CE 10 dce 2015 Carry and Overflow Examples • We can have carry without overflow and vice-versa • Four cases are possible (Examples are 8-bit numbers) 0 0 1 1 15 + 1 1 0 0 1 1 15 + 0 0 0 1 1 0 248 (-8) 0 1 1 23 0 0 1 Carry = Overflow = Carry = 1 1 0 1 79 + Overflow = 1 1 1 218 (-38) + 0 0 0 64 0 1 1 157 (-99) 0 1 1 143 (-113) 1 1 1 Carry = Overflow = Computer Architecture – Chapter Carry = 119 Overflow = © Spring 2015, CE 25 dce 2015 Range, Carry, Borrow, and Overflow • Unsigned Integers: n-bit representation Numbers < Numbers > max Borrow = Subtraction Finite Set of Unsigned Integers Carry = Addition max = 2n–1 = • Signed Integers: n-bit 2's complement representation Numbers < Numbers > max Negative Overflow Finite Set of Signed Integers n-1 = -2 Computer Architecture – Chapter Positive Overflow max = 2n-1–1 © Spring 2015, CE 26 dce 2015 Character Storage • Character sets – – – – Standard ASCII: 7-bit character codes (0 – 127) Extended ASCII: 8-bit character codes (0 – 255) Unicode: 16-bit character codes (0 – 65,535) Unicode standard represents a universal character set • Defines codes for characters used in all major languages • Used in Windows-XP: each character is encoded as 16 bits – UTF-8: variable-length encoding used in HTML • Encodes all Unicode characters • Uses byte for ASCII, but multiple bytes for other characters • Null-terminated String – Array of characters followed by a NULL character Computer Architecture – Chapter © Spring 2015, CE 27 dce 2015 Printable ASCII Codes ! " # A B C D E F $ % & ' ( ) * + , - / 3 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ space DEL  Examples:  ASCII code for space character = 20 (hex) = 32 (decimal)  ASCII code for 'L' = 4C (hex) = 76 (decimal)  ASCII code for 'a' = 61 (hex) = 97 (decimal) Computer Architecture – Chapter © Spring 2015, CE 28 dce 2015 Control Characters • The first 32 characters of ASCII table are used for control • Control character codes = 00 to 1F (hexadecimal) – Not shown in previous slide • Examples of Control Characters – Character is the NULL character  used to terminate a string – Character is the Horizontal Tab (HT) character – Character 0A (hex) = 10 (decimal) is the Line Feed (LF) – Character 0D (hex) = 13 (decimal) is the Carriage Return (CR) – The LF and CR characters are used together • They advance the cursor to the beginning of next line • One control character appears at end of ASCII table – Character 7F (hex) is the Delete (DEL) character Computer Architecture – Chapter © Spring 2015, CE 29 dce 2015 Representing Big (and Small) Numbers • What if we want to encode the approx age of the earth? 4,600,000,000 or 4.6 x 109 or the weight in kg of one a.m.u (atomic mass unit) 0.0000000000000000000000000166 or 1.6 x 10-27 There is no way we can encode either of the above in a 32-bit integer • Floating point representation (-1)sign x F x 2E – Still have to fit everything in 32 bits (single precision) s E (exponent) bit bits F (fraction) 23 bits – The base (2, not 10) is hardwired in the design of the FPALU – More bits in the fraction (F) or the exponent (E) is a trade-off between precision (accuracy of the number) and range (size of the number) Computer Architecture – Chapter © Spring 2015, CE 30 dce 2015 Real Numbers • Conversion from real binary to real decimal • – 1101.10112 = – 13.687510 • since: • 11012 = 23 + 22 + 20 = 1310 and • 0.10112 = 2-1 + 2-3 + 2-4 = 0.5 + 0.125 + 0.0625 = 0.687510 • Conversion from real decimal to real binary: • +927.4510 = + 1110011111.01 1100 1100 1100 … • 927/2 = 463 + 1/2

Ngày đăng: 08/04/2023, 06:21