0% found this document useful (0 votes)
56 views108 pages

NMCNTT 3 NumeralSystems and DataStorage - Update

This document provides an overview of numeral systems and data storage. It discusses how computers store data at the most basic level using bits and bit patterns. It explains that computers use the binary numeral system to represent all digital data as strings of 0s and 1s. These 0s and 1s are stored in memory units called bits. Larger components like gates and flip-flops are used to store and manipulate individual bits. The document also discusses how computers map different types of data like text, numbers, images and sound to these bit patterns to represent the information digitally.

Uploaded by

Đức Hoàng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views108 pages

NMCNTT 3 NumeralSystems and DataStorage - Update

This document provides an overview of numeral systems and data storage. It discusses how computers store data at the most basic level using bits and bit patterns. It explains that computers use the binary numeral system to represent all digital data as strings of 0s and 1s. These 0s and 1s are stored in memory units called bits. Larger components like gates and flip-flops are used to store and manipulate individual bits. The document also discusses how computers map different types of data like text, numbers, images and sound to these bit patterns to represent the information digitally.

Uploaded by

Đức Hoàng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 108

Session 2: Numeral Systems and

Data Storage
Content
 Bits and their Storage
 Bits, Gates, Flip-Flop
 Main Memory
 Representing Information as Bit Patterns
 Text, number, images, sound
 Binary System
 Storing Integers
 Storing Fractions
 Mass Storage
Question

 How computers store data?


 Number, text, image, sound, video

 How computers can mapping data to the


real world?
Bits and their storage

 Bits
 Gates
 Flip-flop
Bits

 Binary uses two digits: 0 and 1.


 bit (Binary Digit): smallest unit storing
information.
 Can be stored in memory (cell) or register.
 Register 1 byte (8 bit) or 1 word (16 bit),
etc.

5
Bits

 Why using 2 digits 0 and 1 to encode


data?

 Electronic implementation
0 1 0

1.1V
0.9V

0.2V
0.0V

Nguồn: Computer System – A Programmer’s Perspective, 3e


Bits

 Easily to encode:
 Numeric value : 1 & 0
 Boolean value : true & false
 Voltage : high & low
 Punched card : punched & not punched

 Data → encode using binary system to


store in computers
Bits – Boolean Operations
 An operation that manipulates one or more
true/false values
 Bit 0 ~ False
 Bit 1 ~ True

 Specific operations : AND, OR, XOR, NOT

 Why Boolean operations?


 Computers are built by small components
 These components can process Boolean
operations quite fast

8
Bits – Boolean Operations

Source: Computer Science - An Overview, 12e

9
Gates
 A device that computes a Boolean operation
 Often implemented as (small) electronic circuits:
 Including: resistor (điện trở), transistor (bòng bán
dẫn), Capacitor (tụ điện), diot (điốt), …
 0 & 1 ~ voltage

Nguồn: Wikipedia

10
A pictorial representation of
gates

Nguồn: Computer Science - An Overview, 12e

11
Example – Simple circuit

Source Chun-Jen Tsai, ics12, National Chiao Tung University

12
Quiz

 What are the names of these gates?


Quiz

 What input bit patterns will cause the


following circuit to produce output of 1?
Flip-Flop
 A circuit built from gates that can store one
bit
 A circuit producing output (or “preserved”) 0
or 1, but remain constant until the pulse from
another circuit makes it change to another
value
 One input line is used to set
its stored value to 1 (output is 1)
 One input line is used to set
its stored value to 0 (output is 0)
 While both input lines are 0, the
most recently stored value is preserved
source: Computer Science - An Overview, 12e

15
A simple flip-flop circuit
Flip-Flop

 Setting the output of a flip-flop to 1

Source: Computer Science - An Overview, 12e

17
Flip-Flop

 Setting the output of a flip-flop to 0

Nguồn: Computer Science - An Overview, 12e

18
Quiz - Flip-Flop?
• If upper input is 1 and lower input is 0,
what is the output?

Source: Computer Science - An Overview, 12e

19
Quiz- Flip-Flop?

Source:wikipedia

20
Flip-flop - Activity
Hexadecimal Notation

 Hexadecimal notation: A shorthand


notation for long bit patterns
 Divides a pattern into groups of four bits each
 Represents each group by a single symbol

 Example: 10100011 becomes A3


The hexadecimal coding system
Bit pattern Hexadecimal
representation
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
Quiz

 What bit patterns are represented by the


following hexadecimal patterns?
 5FD97
 610A
 ABCD
 0100
MAIN MEMORY
Introduction

 We know
 How machines encode information into chain
of bits
 Basic storage devices

 So
 To store data, machines need to have a
million of circuits (a circuit stores 1 bit)
→ Place containing these bits is called Main
Memory

26
Introduction
 In additional to Flip-flops, machines have
other storage devices (called external
memory)
 Magnetic, optical, flash deices

 Storage devices
 Volatile memory (bộ nhớ khả biến)
 Requires power to maintain the stored information
 Non-volatile memory (bộ nhớ bất khả biến)
 Can retrieve stored information even after having
been power cycled

27
Main memory cells
 Cell: A unit of main memory (typically 8 bits
which is one byte)
 Most significant bit: the bit at the left (high-order) end
of the conceptual row of bits in a memory cell
 Least significant bit: the bit at the right (low-order)
end of the conceptual row of bits in a memory cell
 Organization of a byte-size memory cell
 Size 8 bits (1 byte)
 Sequence of bits

28
Main memory address

 Address: A “name” that uniquely identifies


one cell in the computer’s main memory
 “Names” are actually
numbers

 These numbers are


assigned consecutively
starting at zero

 Numbering the cells in this


manner associates an order
to the memory cells
Source: Computer Science - An Overview, 12e

29
Terminology

 Random Access Memory (RAM)


 Memory in which individual cells can be
easily accessed in any order

 Dynamic Memory (DRAM)


 RAM composed of volatile memory

30
Measuring memory capacity

0
1 bit 2

1 0
2 bit 22

2 1 0
3 bit 23

n-1 5 4 3 2 1 0
n bit … 2n

0…000 → 1…111 = 2n – 1 31
Measuring memory capacity

Capacity Value
Byte B 8 bit
KiloByte KB 210 B = 1024 Byte
MegaByte MB 210 KB = 220 Byte
GigaByte GB 210 MB = 230 Byte
TeraByte TB 210 GB = 240 Byte
Peta PB 210 TB = 250 Byte
Exabyte EB 210 PB= 260 Byte
32
REPRESENTING INFORMATION
AS BIT PATTERNS
Representing Text

 Each character (letter, punctuation, etc.)


is assigned a unique bit pattern
 ASCII: Uses patterns of 7-bits to represent
most symbols used in written English text
 ISO developed a number of 8 bit extensions
to ASCII, each designed to accommodate a
major language group
 Unicode: Uses patterns of 16-bits to
represent the major symbols used in
languages world wide (UTF-8, UTF-16,…)
The message “Hello.” in ASCII
Storage - Represent

 Storage and processing: bit

 Display/represent: character
 Need to have a map table between the
two, do the mapping between numerical
values and character values.

 ASCII and Unicode.


36
ASCII
 American Standard Code for Information
Interchange.

 First edition was published in 1963.

 Based on the English alphabet (‘a’– ‘z’, ‘A’ – ‘Z’).

 ASCII encodes 128 specified characters into


seven-bit integers (digits 0 to 9, lowercase letters
a to z, uppercase letters A to Z, and punctuation
symbols).
37
ASCII – Characters
 Printing characters
 ‘ ’ (blank): 32 (0x20)
 ‘0’ -> ‘9’: 48 (0x30) -> 57 (0x39)
 ‘A’ -> ‘Z’: 65 (0x41) -> 90 (0x5A)
 ‘a’ -> ‘z’: 97 (0x61) -> 122 (0x7A)

 Non-printing/control characters
 null: 0
 ‘ ’ (tab): 9
 enter/ line feed: 10
 carriage return: 13

38
ASCII

 ASCII extent: 256 characters.


 128 as the first edition.
 128 extent to characters including: Greece
(‘α’, ‘β’, ‘π’, …), currency (‘£’, ‘¥’, …), …

 ASCII cannot represent characters in


other languages such as Vietnamese,
Russian, Japanese, Arabic, etc.

39
Unicode

 Unicode is a computing industry standard


for the consistent encoding,
representation, and handling of text
expressed in most of the world's writing
systems.
 Containing 1.114.112 code points, divived
into 17 regions, each has 65535 (216)
code points.

40
Unicode

 There are different in using the Unicode,


depending on the storage size of code
point

 UTF – 8: storage size from 1 -> 4 Bytes.


 UTF – 16: storage size 2 Bytes.
 UTF – 32: storage size 4 Bytes.

41
Unicode and Vietnamese

 Unicode contains Vietnamese code points


is at:

 http://vietunicode.sourceforge.net/charset/
v3.htm

42
Unicode - Font

 Each Unicode set has different ways to be represented.

 Unicode is implemented as a digital data file containing


a set of graphically related glyphs, characters, or
symbols.

 Fonts support Unicode (with Vietnamese) :


 Times New Roman,
 Arial,
 Tahoma,
 …

43
Representing Numeric Values

 Binary notation: uses bits to represent a


number in base two
 Limitations of computer representations of
numeric values
 Overflow: occurs when a value is too big to
be represented
 Underflow: occurs when a value is too small
to be represented
 Truncation: occurs when a value cannot be
represented accurately
Representing Images

 Bit map techniques


 Pixel: short for “picture element”
 Encoding
 RGB
 Luminance (cường độ sáng) and chrominance (độ
đậm/nhạt của màu)
 Vector: can zoom in/out → not affected to
the quality
 Scalable
 TrueType and PostScript
Representing Sound
 Sampling techniques: get the amplitude of the sound
wave at regular intervals and store the series of values
 Used for high quality recordings
 Records actual audio
 Sampling rate (Hertz – Hz)
 Telephone: 8,000 samples/second – 8 KHz
 Music: 44,100 samples/second – 44,1 KHz
 High definition: 16 bits/sample
 Stereo: 32 bits/sample
Quiz

 Suppose a stereo recording of one hour


of music is encoded using a sample rate
of 44,100 samples per second as
discussed.
 What is the size of the encoded version?
BINARY SYSTEM
Binary system

 The traditional decimal system is based


on powers of ten.
 The Binary system is based on powers of
two
 The base 10 and the binary system
Decoding the binary representing
100101
Base 10 to binary
Binary additional facts

 Additional table
+ 0 1
0 0 1
1 1 10
Decoding the binary representation
(Binary to base 10)

1010.112 = 1*23+0*22+1*21+0*20+1*2-1+1*2-2
1010.112 = 8+0+2+0+0.5+0.25 = 10.7510
Quiz

 Convert each of the following base 10


representations to its equivalent binary
form:
 32
 15
 27
 53
Quiz

 Convert each of the following binary


representations to its equivalent base 10
form:
 11.01
 101.111
 10.1
 110.011
 0.101
Quiz

 Express the following values in binary


notation:
Quiz

 Binary to base 10
 21.12510
STORING INTEGERS
Unsigned Integers

 Representations of quantities are always


positive
 Ex: height, weight, ASCII code, etc.
 All bits are used for value
 Max value of 1 unsigned byte:
 1111 11112 = 28 – 1 = 25510
 Max value of 1 unsigned word (2 bytes):
 1111 1111 1111 11112 = 216 – 1 = 6553510
Signed Integers

 Storing/representing of negative and


positive integers
 The leftmost bit is used to represent the
sign
 Ex:
 0 positive: 0101 0011
 1 negative: 1101 0011
 Negative integers stored in machine as
two’s complement or excess notation
Two’s complement notation
systems
 Leftmost bit: sign bit

 One’s complement :
 Changing all the 0s to 1s, all the 1s to 0s.
 Ex: 0110 and 1001 are complements

 Two’s complement: add 1 to the one’s


complement
 Ex: 1001 + 0001 = 1010
One’s and two’s complements

5 (1 byte) 0 0 0 0 0 1 0 1
One’s complement of 5 1 1 1 1 1 0 1 0

+ 1

Two’s complement of 5 1 1 1 1 1 0 1 1
+ 5 0 0 0 0 0 1 0 1

Result 1 0 0 0 0 0 0 0 0
Coding the value -6 in two’s
complement notation using 4 bits
Two’s complement notation
systems
Addition problems converted to
two’s complement notation
Quiz

 Convert each of the following two’s


complement representations to its
equivalence base 10 form:
 00011
 01111
 11100
 11010
 00000
 10000
Quiz

 Convert to two’s complement form using


patterns of 8 bits:
6
 -6
 -17
 13
 -1
0
Quiz

 What are the largest and smallest


numbers that can be stored if the machine
uses bit patterns of the following lengths?
 A. four
 B. six
 C. eight
Min and max of signed integers

N bits minimum maximum


8 -27 = -128 27 - 1 = +127
16 -215 = -32,768 215 - 1 = +32,767
32 -231 = -2,147,483,648 231 - 1 = +2,147,483,647

64 -263 = - 263-1 =
9,223,372,036,854,775,808 +9,223,372,036,854,775,807
Min and max of unsigned integers

n Minimum Maximum
8 0 28 - 1 = 255
16 0 216 - 1 = 65,535
32 0 232 -1 = 4,294,967,295
64 0 264 - 1 = 18,446,744,073,709,551,615
Excess (K-bias)
 Choose K (a positive integer) to allows
operations on the biased numbers to be the
same as for unsigned integers, but represents
both positive and negative values
 The remaining n bits represents the biased
value (n is the length of bit pattern)
 Excess representations are now primarily used
for the exponent of floating-point numbers
Excess (K-bias)
Ex: Suppose that n =8, K=128, how to represent a
number in binary
Positive number: N = 25 (decimal)
N+K = 25 + 128 = 153
The bit binary pattern is  10011001
Negative number: N = -25 (decimal)
N+K = -25 + 128 = 103
The bit binary pattern is  01100111
Excess

Two’s complement Excess


Excess
Two’s complement Excess
STORING FRACTIONS
Fractions

 Floating-points:
 Consisting of a sign bit, a mantissa field, and
an exponent field.
 Radix point: used to separate integer part
and the fraction part of a number
 Mantissa: also fraction/significant
Example 1

 01101011
 Signed bit: 0
 Exponent: 110
 Mantissa: 1011

 .1011
 110 = 2 (excess with 3-bit)
 10.11 = 2 ¾
Example 2

 00111100
 Signed bit: 0
 Exponent: 011
 Mantissa: 1100

 .1100
 011 = -1 (excess with 3-bit)
 .01100 = 3/8
Example 3

 Encode 1⅛
 Convert to binary 1.001
 Mantissa: _ _ _ _ 1 0 0 1
 From left to right, start with leftmost bit 1
 Radix point: from .1001 to 1.001
 → Exponent: +1 = 101 (excess 3-bit)
 Signed bit: 0

 1 ⅛ = 01011001
Encoding the value 2 5⁄8
→ Truncation error

0 110 1010

21/2

21/2 + 1/8 + 1/8 = ?


Floating points
 Single precision floating point (32 bits)
 1 bit (sign) + 8 bits (exponent) + 23 bits (mantissa)
 Value: from 10-37 to 1038
 Precision: 7 decimal fraction

 Double precision floating point (64 bits)


 15 decimal fraction
Fractions

 Single-precision : 32 bits
s exp frac
1 8-bits 23-bits

 Double-precision : 64 bits
s exp frac
1 11-bits 52-bits

 Extend-precision : 80 bits (Intel only)


s exp frac
1 15-bits 63 or 64-bits
IEEE-754 32-bit Single-Precision
Floating-Point Numbers
 IEEE-754:
N = (-1)^S x 1.F x 2^(E-127)

 S: Sign bit
 F: Fraction part
 E: Exponent part
 127 = 2 8-1 (excess 8-bit)
Example 1

 0 10000000 110 0000 0000 0000 0000 0000

Sign bit S = 0 ⇒ positive number


E = 1000 0000B = 128D
Fraction is 1.11B (with an implicit
leading 1) = 1 + 1×2^-1 + 1×2^-2 = 1.75D

The number is +1.75 × 2^(128-127) = +3.5D


Example 2
 1 01111110 100 0000 0000 0000 0000 0000

Sign bit S = 1 ⇒ negative number


E = 0111 1110B = 126D
Fraction is 1.1B (with an implicit leading 1) =
1 + 2^-1 = 1.5D

The number is -1.5 × 2^(126-127)=-0.75D


IEEE-754 64-bit Double-Precision
Floating-Point Numbers
 Exponent: excess – 1023
 Fraction: implicit leading bit (before radix
point).
 N = (-1)^S x 1.F x 2^(E-1023)
Min and Max of Floating-Point
Numbers

Precision Min Max


Single 1.1754 x 10-38 3.40282 x 1038
Double 2.2250 x 10-308 1.7976 x 10308
COMMUNICATION ERRORS
Communication error
 Happening when:
 Data transferred between components in computer
 Storing data
 Bits received are not the same with originals
 Reasons:
 Dirt on disc surface
 Broken circuit makes reading / writing inaccurate
 Data transmission line broken
 Radiation changes the sequence of bits on main
memory
Techniques

 Parity bits (even vs odd)


 Checkbytes
 Error correcting codes
Parity bits

 Error detection is based on: odd-number


of bits 1 and even-number of bits 1 is
found → there must be an error.
Checkbyte

 Set of parity bits


 Each parity bit is scattered in the bit
patterns
 For example, a parity bit is associated with
every eighth bit in the bit patterns

 Checksum
Error-correcting code

 Hamming distance (of two bit patterns):


 Number of bits in which the patterns differ.

 Example:
 Hamming(000000, 001111) = 4
 Hamming(10101100, 01100100) = 3
Error-correcting code
Error-correcting code

D is the answer because it has smallest distance


Quiz

 The following bytes were originally


encoded using odd parity. In which of
them do you know that an error has
occurred?
Quiz

 Using the error-correcting code presented


before, decode the following messages:
Quiz

 Construct a code for the characters A, B,


C, D using bit patterns of length five so
that the Hamming distance between any
two patterns is at least three.
MASS STORAGE
Mass Storage

 On-line versus off-line


 Typically larger than main memory
 Typically less volatile than main memory
 Typically slower than main memory
 Typically lower cost than main memory
Mass Storage Systems

 Magnetic Systems
 Disk
 Tape
 Optical Systems
 CD
 DVD
 Flash Technology
 Flash Drives
 Secure Digital (SD) Memory Card
Magnetic disk storage system
Magnetic disk storage system

 Seek time
 Time needed to position the read/write head
over the correct track
 Latency
 Time for the beginning of the desired sector
to rotate under the read/write head
 Transfer time
 Time for the entire sector to pass under the
read/write head and have its contents read
into or written from memory
Magnetic disk storage system
 Given:
 Rotation speed = 7,200 rev/min=120 rev/sec = 8.33 msec/rev
 Arm movement time = 0.02 msec to move to an adjacent track
 On average, the read/write head must move about 300 tracks
 Number of tracks/surface = 1,000
 Number of sectors/track = 64
 Number of bytes/sector = 1,024
 Seek time
 Best case = 0 msec;
 Worst case = 999*0.02=19.98 msec
 Average case = 300*0.02 = 6 msec
Magnetic disk storage system
 Given:
 Rotation speed = 7,200 rev/min=120 rev/sec = 8.33 msec/rev
 Arm movement time = 0.02 msec to move to an adjacent track
 On average, the read/write head must move about 300 tracks
 Number of tracks/surface = 1,000
 Number of sectors/track = 64
 Number of bytes/sector = 1,024
 Latency
 Best case = 0 msec;
 Worst case = 8.33 msec
 Average case = 4.17 msec
Magnetic disk storage system
 Given:
 Rotation speed = 7,200 rev/min=120 rev/sec = 8.33 msec/rev
 Arm movement time = 0.02 msec to move to an adjacent track
 On average, the read/write head must move about 300 tracks
 Number of tracks/surface = 1,000
 Number of sectors/track = 64
 Number of bytes/sector = 1,024
 Transfer time
 1/64 * 8.33 msec = 4.17 msec
Magnetic tape storage

You might also like