Principles of Computer Organization (six)

Data representation

Data encoding and representation

  • Need to represent objects in a computer
    program, integer, floating point, character (string), the logic value
    represented by encoding
  • Representation
    is represented by two states of the digital circuit
    layer abstraction by the computer to identify different content
  • Coding principles
    few simple basic symbols
    certain rules
    represent a large number of complex information
    easy to use

Coded representation

  • The basic elements of
    0,1 two symbolic
  • Character
    26 letters -> 5
    / lower case + other symbols = 7bits (in 8)
    text in other languages in the world = 16bits (unicode)
  • Unsigned integer (0, 1, ..., 2 n 1 2^{n}-1
  • The logic value
    0-false 1-true
  • colour
  • Location / address / command
  • But as the only representative of n 2 n 2^{n} different objects

Logical Data

  • Logical
    true true
    false false
  • Data are expressed
    . 1
    0
  • Data operations
  • And, or, not
x Y x and y x or y The non-x
0 0 0 0 1
0 1 0 1 1
1 0 0 1 0
1 1 0 1 0

Character data

  • Important man-machine interface

  • Consisting of symbols
    encoded for each symbol, is converted by the input / output device
    typically in the form of a string stored in a computer memory

  • Standard character set encoding
    the ASCII
    the UNICODE
    UTF-. 8

  • ascii characters coded
    using 7-bit binary code, one byte
    represents a Western character 128
    ascii code character set
    Here Insert Picture Description

  • unicode encoded
    using 16 bits represent a character, the character can represent 65536
    the entire space is divided into encoding blocks, each block is a multiple of 16, according to block allocated
    Reserved 6400 yards points for local use
    still can not cover all of the characters

  • utf-8 encoded

Number of characters Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
7 0ddddddd
11 110ddddd 10dddddd
16 1110dddd 10dddddd 10dddddd
21 11110ddd 10dddddd 10dddddd 10dddddd
26 111110dd 10dddddd 10dddddd 10dddddd 10dddddd
31 1111110d 10dddddd 10dddddd 10dddddd 10dddddd 10dddddd

Variable-length character encoding, improve utilization of storage space
character is determined by the length of the first byte of
the character outside the first byte, are "10" begins, self-synchronization
scalability
becomes dominant Internet character set

Represents a numeric data

  • Fixed point
    decimal position is fixed
    integer
    fixed-point decimal

  • Floating point
    decimal floating position

  • Binary representation of the integer
    two states and a binary 0. 1
    n-bit available 2 n 2^{n} combinations, may represent 2 n 2^{n} integers

Machine representation True value
0 0
01 1
10 2
11 3
100 4
101 5
1{n} 2 n 1 2^{n}-1
  • evaluation standard
  • Unsigned
  • It represents the range
  • Intuition
  • Easy to implement arithmetic operations
    • Signed number
      represents the range of
      visual
      negative balance
      facilitate arithmetic

Binary notation

Binary notation
i = m k D i R i \sum_{i=m}^{-k}{D_{i}R^{i}}
N represents a numerical value
and r represents the radix number
i represents the bit number of symbols arranged
D i D_{i} Is the bit number of one symbol position i
r i r^{i} is a value represented by a 1 in the bit number i

  • Common number system
    decimal, binary, octal, hexadecimal

Hexadecimal and binary notation

Binary
r = 2, 01 basic symbols
octal
r = 8, the basic symbol 01234567
decimal
r = 10, the basic symbol 0123456789
hex
r = 16, the basic symbol 0 1 2 3 4 5 6 7 8 9 ABCDEF
computer binary

Into binary representation of an integer
specific to the n-bit unsigned binary integer, such
b n 1 b n 2 . . . b 1 b_{n-1}b_{n-2}...b_{1}
among them b i b_{i} 0 or 1 is
represented by the value N = i = 0 n 1 b i 2 i \sum_{i=0}^{n-1}{b_{i}2^{i}}
range represented by 0 ------ 2 n 1 2^{n}-1 , a total of 2 n 2^{n} number.

How to represent a signed integer

  • We needed to represent a symbol bits
    highest bit
    0 represents an integer, 1 for negative
  • Other bits represent data

Anti-code complement the original code

Negative forms
of the original code: the absolute value of the sign bit number ||
anti-code: the symbol bit values ||
complement: the inverted least significant bit + 1

coding Original code Inverted Complement
000 0 0 0
001 1 1 1
010 2 2 2
011 3 3 3
100 -0 -3 -4
101 -1 -2 -3
110 -2 -1 -2
111 -3 -0 -1

Nature complement

Corresponding to the complement of the true value

  • Realistic complement value
    N = b n 1 2 n 1 + i = 0 n 2 b i 2 i -b_{n-1}*2^{n-1}+\sum_{i=0}^{n-2}{b_{i}2^{i}}
  • True value twos complement
    positive numbers complement absolute value of the original code is
    negative complement absolute value of the original code bit negated, then add 1 to the least significant bit
  • Complement addition operation of
    the adder sign bit and data bits calculated in the same
    [x + y] Complement = [x] Complement + [y] Complement
    [x] and complement [the -X-] Complement
    [x] in the same complement sign bit, inverted bit by bit, then the lowest bit plus 1, can be obtained [the -X-] complement

Complement subtraction
[XY] Complement = [x] Complement + [- y] Complement

Big-endian and little-endian

0x12345678

Small end large end 78563412 12345678

He published 185 original articles · won praise 18 · views 160 000 +

Guess you like

Origin blog.csdn.net/pk_20140716/article/details/104649666