Data Representation - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Data Representation

Description:

Concatenate the remainders to form the binary representation ... sequence of ASCII bytes representing the digits of the number expressed in some radix ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 18
Provided by: timma87
Category:

less

Transcript and Presenter's Notes

Title: Data Representation


1
Data Representation
  • Assembly Language Programming
  • University of Akron
  • Dr. Tim Margush

2
Binary Numerals
  • 1101101b
  • Bits are numbered from the right b6b5b4b3b2b1b0
  • Subscripts represent the place value
  • b6 has place value 26
  • Conversion to decimal is done by evaluating the
    polynomial
  • b626 b525 b424 b323 b222 b121 b020
  • In this case, 6432841 109d

3
Decimal to Binary
  • 109d is converted to binary by repeated divisions
    by 2
  • make note of the remainders
  • Stop when you reach 0
  • Concatenate the remainders to form the binary
    representation
  • First remainder is least significant bit
  • 109d 1101101b
  • 109 / 2 54 r 1
  • 54 / 2 27 r 0
  • 27 / 2 13 r 1
  • 13 / 2 6 r 1
  • 6 / 2 3 r 0
  • 3 / 2 1 r 1
  • 1 / 2 0 r 1

4
Binary and Hexadecimal
  • Binary to Hex
  • Group bits by fours (starting with least
    significant bits)
  • Add leading zeros as necessary to complete the
    last group
  • Convert each group to the equivalent hex digit
  • Hex to Binary
  • Expand each hex digit to the equivalent 4-bit
    binary form
  • You may omit leading zeros of leftmost digit
  • 0100 1110b 4Eh
  • 37h 0011 0111b
  • (or 110111b)

5
Character Data
  • American Standard Code for Information
    Interchange (ASCII)
  • a 7-bit binary code for a set of 128 characters
  • usually occupy a byte of storage
  • leading bit may be ignored or used differently by
    various programs
  • a sequence of bytes containing ASCII codes is
    referred to as an ASCII string

6
Numeric Data
  • Binary storage
  • twos complement, ones complement, sign and
    magnitude, or biased representations
  • ASCII storage
  • sequence of ASCII bytes representing the digits
    of the number expressed in some radix
  • Binary Coded Decimal
  • sequence of nybbles representing digits 0-9 of
    the number

7
Binary Storage
  • A pre-arranged storage size is used
  • typically byte, word, doubleword, or quadword
  • Represent a number in base two and encode the
    bits
  • 197d is 11000101b
  • at least 8 bits will be required to store this
    number (leading zeros are added if necessary to
    fill additional bits for larger storage sizes)

8
Signed vs Unsigned Codes
  • Unsigned Byte
  • all 8 bits used to represent the magnitude of the
    number
  • Minimum 0 (zero) is coded as 00000000b
  • Maximum 255 is coded as 11111111b
  • Signed Byte
  • twos complement code is most common
  • only 7 bits are used for the magnitude
  • Minimum -128 is coded as 10000000b
  • Maximum 127 is coded as 01111111b
  • Zero is 00000000b

9
Understanding Twos Complement Code
  • Codes for positive numbers are identical to
    unsigned codes
  • at least one leading zero is required
  • Negative numbers are coded by adding 256 and
    writing the unsigned code of the result
  • Code for 107
  • 107d 1101011b
  • code 01101011 (6Bh)
  • Code for -107
  • -107 256 149
  • 149d 10010101b
  • code 10010101b (95h)
  • What is 6Bh 95h?

10
Twos Complement Sign Change
  • The 2s Complement codes for x and -x add to a
    power of 2
  • 8-bit code c(-c)28
  • 16-bit code c(-c)216
  • (-c)2n-c(2n-1)-c1
  • Note that (2n-1) is 1111..1b, making subtraction
    a cinch!
  • Roles of (-c) and c can be reversed
  • Change Sign Rule I
  • Subtract from 2n
  • Change Sign Rule II
  • Flip all the bits
  • Add 1
  • Change Sign Rule III
  • Scan right to left to the first bit with value 1
  • Flip all bits to its left

11
Decoding Twos Complement Data
  • 0001011010111000b
  • Leading zero indicates value is positive
  • simply convert to decimal
  • 15B8h 5560d
  • Data 5560
  • 1110100101001000b
  • Leading one indicates value is negative
  • apply change sign rule, then convert to decimal
  • 0001011010111000b
  • last 4 bits unchanged
  • 15B8h 5560d
  • Data -5560

Dont forget the minus!
12
Storage Sizes and Ranges
  • Unsigned Integer
  • Byte
  • 0 to 255
  • Word
  • 0 to 65,535
  • Doubleword
  • 0 to 4,294,967,295
  • Quadword
  • 0 to 18,446,744,073,709,551,615
  • Signed (2s Complement Code)
  • Byte
  • -128 to 127
  • Word
  • -32,768 to 32,767
  • Doubleword
  • -2,147,483,648 to 2,147,483,647
  • Quadword
  • -9,223,372,036,854,775,808 to 9,223,372,036,854,77
    5,807

13
Basic Addition
  • Numbers can be added in any number base
  • Use the same algorithm you practiced in second
    grade!
  • Binary Example
  • c c c c
  • 10101
  • 1111
  • 100100
  • Hex Example
  • c c
  • 3CF02
  • 435C9
  • 804CB
  • A carry occurs when the sum is sixteen or greater

Watch Carries
00 0 01 1 10 1 11 10 111 11
14
Basic Subtraction
  • Just remember how to borrow.
  • Take into account the place values!
  • Hex example
  • b b
  • FCF02
  • -435C9
  • B9939
  • Binary subtraction is easy, but tricky!
  • Borrows are worth two but sometimes you need to
    borrow from afar!
  • b b b b b
  • 1101000011
  • - 1101001
  • 1011011010

A borrow adds sixteen
15
Twos Complement Arithmetic
  • Adding or subtracting integers represented by
    n-bit codes gives an n-bit result
  • These operations use the coded representations,
    treating them as unsigned values
  • Addition is accomplished by adding the codes,
    ignoring any final carry
  • Subtraction is simplest if you change the sign
    and add

16
Example of Twos Complement Arithmetic
  • 111100001101
  • 011101101001
  • 011001110110
  • These are 12-bit, twos complement codes
  • A negative and positive quantity are being added
  • The result is positive
  • Decode and check!
  • F23C F23C
  • - 2CF0 D310
  • ? C54C
  • These are 16-bit, twos complement codes
  • The equivalent addition problem adds two
    negatives and the result is negative
  • Decode and check!

17
Example Decoded!
  • Binary Dec
  • 111100001101 -243
  • 011101101001 1897
  • 011001110110 1654
  • Decoding the negative number
  • 111100001101
  • -(000011110011)
  • -243
  • Hex Decimal
  • F23C (-3524)
  • - 2CF0 - 11504
  • C54C - 15028
  • Decoding F23C
  • 1111001000111100
  • -(0000110111000100)
  • -3524
Write a Comment
User Comments (0)
About PowerShow.com