Anda di halaman 1dari 61

DATA STORAGE

Information
Information is best understood as
what it takes to answer a question.
The simplest question has a yes or
no answer. Therefore a bit is the
natural measure of information.
Term first used by John Turkey in
1946.
Concatenation of binary digit.

Usage of bits
Computers are sometimes classified by the
number of bits they can process at one
time. "32 bit processor"
Graphics are also often described by the
number of bits used to represent each dot.
a bit can take the values 0 or 1, thus it can
describe 2 possibilities
The first chips used to process 8 bits at a
time. It become customary to refer to them
as a byte

Many bytes
Larger units are
Kilo byte is 2 power 10 bytes (=1024
bytes)
Mega bytes is 2 power 20 bytes
Giga bytes is 2 power 30 bytes
Tera byte is 2 power 40 bytes

Character Representation: ASCII,


EBCDIC, and Unicode
The most common character
representation is ASCII, which stands
for American Standard Code for
Information Interchange.
The other reason we use ASCII is
because of the letter "S" in ASCII,
which stands for "standard".
Standards are good because they
allow for common formats that
everyone can agree on.

the lowercase letters are contiguous


('a' through 'z' maps to 97 through
122). The upper case letters are also
contiguous ('A' through 'Z' maps to
65through 90).
there are only 128 ASCII characters

ASCII Code

0 nul
1 soh
2 stx
3 etx
4 eot
5 enq
6 ack
7 bel
8 bs
9 ht
10 nl
11 vt
12 np
13 cr
14 so
15 si

16 dle 32 sp 48 0
64 @
80 P
96 ` 112 p
17 dc1 33 !
49 1
65 A
81 Q
97 a 113 q
18 dc2 34 "
50 2
66 B
82 R
98 b 114 r
19 dc3 35 #
51 3
67 C
83 S
99 c 115 s
20 dc4 36 $
52 4
68 D
84 T 100 d 116 t
21 nak 37 %
53 5
69 E
85 U 101 e 117 u
22 syn 38 &
54 6
70 F
86 V 102 f 118 v
23 etb 39 '
55 7
71 G
87 W 103 g 119 w
24 can 40 (
56 8
72 H
88 X 104 h 120 x
25 em 41 )
57 9
73 I
89 Y 105 i 121 y
26 sub 42 *
58 :
74 J
90 Z 106 j 122 z
27 esc 43 +
59 ;
75 K
91 [ 107 k 123 {
28 fs 44 ,
60 <
76 L
92 \ 108 l 124 |
29 gs 45 61 =
77 M
93 ] 109 m 125 }
30 rs 46 .
62 >
78 N
94 ^ 110 n 126 ~
31 us 47 /
63 ?
79 O
95 _ 111 o 127 del

char data type is of 1 byte


another character representation that was used
(especially at IBM) was EBCDIC, which stands for
Extended Binary Coded Decimal Interchange
Code
EBCDIC does not store characters
contiguously.so it is a problem
ASCII is that it's biased to the English language
In particular, 8 bits can only represent 256
words, which is far smaller than the number of
words in natural languages.

a new character set called Unicode


is now becoming more prevalent.
This is a 16 bit code, which allows for
about 65,000 different
representations
Unicode:Industry has come together
to work on Unicode, a 2-byte
character set.
C and C++ still primarily use ASCII,
Java has already used Unicode

Binary-Coded Decimal
(BCD)
Four bits per digit

Digit

Bit pattern

0000

Note: the following bit


patterns are not used:

0001

0010

0011

0100

0101

0110

0111

1000

1001

1010
1011
1100
1101
1110
1111

Example
709310 = ? (in BCD)
7

0111

0000

1001

0011

2.1 Introduction
REVIEW:
A bit is the most basic unit of information in a computer.
It is a state of on or off in a digital circuit.
Sometimes these states are high or low voltage
instead of on or off..
A byte is a group of eight bits.
A byte is the smallest possible addressable (can be found
via its location) unit of computer storage.
A word is a contiguous group of bytes.
Words can be any number of bits (16, 32, 64 bits are
common).
A group of four bits is called a nibble (or nybble).
Bytes, therefore, consist of two nibbles: a high-order
nibble, and a low-order nibble.

Chapter 2: Data Representation

12

Numbering Systems
Number System defines a set of values used to represent
quantity.
Base or Radix:The total number of digits available in a
number system .
Decimal Number System:
There are 10 digits i.e 1, 2, 3, 4, 5, 6, 7, 8, 9 available in
decimal number system. It is known as Base 10 system. The
value of a digit in a number depends upon its position in the
number e.g. the number 546 in this system is represented as
(546)10
546 = (4*102) + (8*101) + (6*100)
Binary Number System
The Binary Number System contains 2 unique digits 0 and 1. it
is known as Base 2 system.

Octal Number System


There are 8 unique digits available in octal number
system. These are 0, 1, 2, 3, 4, 5, 6, 7. thus, any
number formed is the combination of these digits. It
is known as Base 8 system.
Hexadecimal Number System
There are 16 unique digits available in Hexadecimal
number system. These are 0, 1, 2, 3, 4, 5, 6, 7, 8, A,
B, C, D, E, F where A denotes 10, B denotes
11,F denotes 15. thus any number formed is a
combination of these digits. It is known as Base 16
system.

2.2 Positional Numbering Systems


The decimal number 947 in powers of 10 is:
9 10 2 + 4 10 1 + 7 10 0

The decimal number 5836.47 in powers of 10 is:


5 10 3 + 8 10 2 + 3 10 1 + 6 10 0
+ 4 10 -1 + 7 10 -2

Chapter 2: Data Representation

15

2.2 Positional Numbering Systems


Binary works the same as decimal
The binary number 11001 in powers of 2 is:
1 24+ 1 23 + 0 22 + 0 21 + 1 20
= 16

= 25

When the radix of a number is something other than


10, the base is denoted by a subscript.
Sometimes, the subscript 10 is added for emphasis:
110012 = 2510

Chapter 2: Data Representation

16

Converting Decimal to Binary, Octal and


Hexadecimal
Integer Part
Remainder method
1. Divide the decimal number by the base of the target number
system that is, to convert decimal to binary, divide the decimal
number with 2 (the base of binary number system), 8 for octal
and 16 for hexadecimal.
2. Note the remainder separately as the first digit from the
right. In case of hexadecimal , if the remainder exceeds 9,
convert the remainder into equivalent hexadecimal form. For
e.g., if the remainder is 10 then note the remainder as A.
3. Continually repeat the process of dividing until the quotient
is zero and keep writing the remainders after each step of
division.
4. Finally, when no more division can occur, write down the
remainders in reverse order.

Fractional Part
1. Multiply the fractional part by the value of
the new base.
2. Record the integer part if it exits, else
record 0.
3. Repeat step 1 with the result of the
previous multiplication and then step 2, until
the fractional part becomes 0. in case of
infinite calculations, generally 6 digits are
taken.

Decimal
Binary
conversion

Convert 75 to Binary
2
2
2
2
2
2
2

75
37
18
9
4
2
1
0

remainder

1
1
0
1
0
0
1

1001011

Check
1001011 =1x20 + 1x21 + 0x22 +
1x23 +
0x24 + 0x25 + 1x26
=1 + 2 + 0 + 8 + 0 + 0 +
64
=75

Representation of integers
An integer is a no. with no fractional
part; it can be positive, negative,or
zero.
Set 0 for positive no.
Set 1 for negative no.
Unsigned integer: containing n bits
can have a value between o and 2n-1
ex. With 8 bits, (0255) can be
represented.

2.4 Signed Integer Representation

Signed integer: can be positive or negative


Signed and unsigned numbers are both useful.
For example, memory addresses are always
unsigned.

Chapter 2: Data Representation

24

2.4 Signed Integer Representation


To represent negative values, computer systems
allocate the high-order bit to indicate the sign of a
value.
The high-order bit is the leftmost bit in a byte.
Its also called the most significant bit.
The remaining bits contain the value of the number.

There are three ways in which signed binary


numbers may be expressed:
Signed magnitude,
Ones complement we wont do much with this
here
Twos complement.
Chapter 2: Data Representation

25

2.4 Signed Integer Representation


In an 8-bit word, signed magnitude representation
places the absolute value of the number in the 7 bits
to the right of the sign bit.
In 8-bit signed magnitude,
Positive 3 is:
00000011
Negative 3 is: 10000011

Chapter 2: Data Representation

26

2.4 Signed Integer Representation


Binary addition is as easy as it gets. You need
to know only four rules:
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0,carry 1 to
next more significant dit

The simplicity of this system makes it possible


for digital circuits to carry out arithmetic
operations.
Binary subtraction is as easy as it gets. You
need to know only four rules:
0 - 0 = 0
0 - 1 = 1, borrow 1
Lets see how the addition rules work with signed
1 - magnitude
0 = 1 numbers
1 . -. . 1 = 0
Chapter 2: Data Representation

27

2.4 Signed Integer Representation


Example:
Using signed magnitude binary
arithmetic, find the sum of 2
binary no.

As in decimal arithmetic, find the sum


starting with the rightmost bit and work
left.

In the second bit, we have a carry, so we


note it above the third bit.

Chapter 2: Data Representation

28

2.4 Signed Integer Representation

In this example, we were careful to pick two values whose


sum would fit into seven bits. If thats not the case, we
have a problem.
Example:
The carry from the seventh bit overflows and
is discarded, giving us the erroneous result.

Chapter 2: Data Representation

29

2.4 Signed Integer Representation


Signed magnitude representation
is easy for people to understand,
but needs complicated computer
hardware.
Another disadvantage: it allows
two different representations for
zero: positive zero and negative
zero.
So computers systems employ
complement systems for numeric
value representation.

Chapter 2: Data Representation

4-bit
Binary
1000
1001
1010
1011
1100
1101
1110
1111
0000
0001
0010
0011
0100
0101
0110
0111

Decimal
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
30

2.4 Signed Integer Representation


To express a value in twos complement:
If the number is positive, just convert it to binary
and youre done.
If the number is negative, find the ones
complement (change each of the bits) of the
number and then add 1.
Example:
In 8-bit ones complement, positive 3 is:
00000011
Negative 3 in ones complement is:
11111100
Adding 1 gives us -3 in twos complement form:
11111101.
Chapter 2: Data Representation

31

2.4 Signed Integer Representation


With twos complement arithmetic, all we do is
add our two binary numbers. Just discard any
carries emitting from the high order bit.
Example: Using twos
complement binary arithmetic,
find the sum of +48 and - 19.

We note that 19 in binary is:


ones complement is:
and -19 in twos complement is:

00010011,
11101100(add 1)
11101101.

Chapter 2: Data Representation

32

Multiplication in binary system works


same as decimal system. 0*0=0,
0*1=0, 1*0=0, 1*1=1
Division in binary system works same
as decimal system.

Boolean Logic
Operations

Let

x, y, z

be Boolean

variables. Boolean variables can


only have binary values i.e., they
can have values which are either 0
or 1
For example, if we represent the state of a
light switch with a Boolean variable x, we
will assign a value of 0 to x when the switch
is OFF, and 1 when it is ON

A few other names for the states of


these Boolean variables

Off

On

Low

High

False

True

We define the following logic operations


or functions among the Boolean variables
Name

Example Symbolically
= NOT(x)
x

y
AND z = x AND y
z = x OR y
OR
z = x XOR
XOR y
NOT

xy
x+y
xy

Well define these operations with the help of truth tables

what is the truth table of a logic function


A truth table defines the output of a logic function for all possible inputs

Truth Table for the NOT


Operation
(y true whenever x is false)

x
0
1

y = x

Truth Table for the NOT


Operation

y = x

Truth Table for the AND


Operation
(z true when both x & y true)

z=xy

Truth Table for the AND


Operation

z=xy

Truth Table for the OR


Operation
(z true when x or y or both
true)

z=x+y

Truth Table for the OR


Operation

z=x+y

Truth Table for the XOR


Operation
(z true when x or y true, but not
both)

z=xy

Truth Table for the XOR


Operation

z=xy

Text Editor
A text editor is used to edit plain text
files.
They fall into two general categories:
1 Line editor- it requires a specific line
of text before you modify it.
2 Screen oriented editors- modify any
text by moving the cursor to the
desired location.

Types of text editors


Notepad++ - It is used only in
windows operating system which is
able to provide better features
compared to notepad. It is
completely free and open
source.Advanced features- syntax
highlighting, macros
Emacs: It is used in any operating
system, it has built in macros and
powerful keyboard commands.

Ultra edit- It is user friendly. It


focuses mainly on web development
with built in advanced feature like
HTML,PHP,JAVASCRIPT.
Vi, Textmate, vim, textpad etc are
some more editors.

VI EDITOR
Use vi editor to:
create text files
edit text files

What is vi ?
The visual editor on the Unix.
Before vi the primary editor used on Unix
was the line editor
User was able to see/edit only one line of the
text at a time

The vi editor is not a text formatter (like


MS Word, Word Perfect, etc.)
you cannot set margins
center headings
Etc

Starting vi
Type vi <filename> at the shell
prompt
After pressing enter the command
prompt disappears and you see
tilde(~) characters on all the lines
These tilde characters indicate that
the line is blank

Vi modes
There are three modes in vi
Command mode
Input mode(insert mode)
Execute mode (last line mode)

When you start vi by default it is in


command mode
You enter the input mode through
commands i
You exit the input mode by pressing the
Esc key to get back to the command mode

How to exit from vi


:q <enter> is to exit, if you have not
made any changes to the file
:q! <enter> is the forced quit, it will
discard the changes and quit
:wq <enter> is for save and Exit
:x <enter> is same as above command
ZZ is for save and Exit (Note this
command is uppercase)

Moving Around
You can move around only when you
are in the command mode
Arrow keys usually works(but may
not)
The standard keys for moving
cursor are:

h - for left
l - for right
j - for down
k - for up

Moving Around
w - to move one word forward
b - to move one word backward
$ - takes you to the end of line

Moving Around
Control-d scrolls the screen down
(half screen)
Control-u scrolls the screen up (half
screen)
Control-f scrolls the screen forward
(full screen)
Control-b scrolls the screen
backward (full screen).

Entering text
To enter the text in vi you should
first switch to input mode
To switch to input mode there are
several different commands
a - Append mode places the insertion
point after the current character
i - Insert mode places the insertion
point before the current character

Entering text
I - places the insertion point at the
beginning of current line
o - is for open mode and places the
insertion point after the current line
O - places the insertion point before the
current line
R - starts the replace characters, starting
with current cursor position
r - replace 1 character (under the cursor)
with another character

Editing text
x - deletes the current character
d - is the delete command but pressing
only d will not delete anything you need
to press a second key
dw - deletes to end of word
dd - deletes the current line
d0 - deletes to beginning of line

There are many more keys to be used


with delete command

Compilation and running a VI editor


To compile: CC filename.c
To run : a.out

Anda mungkin juga menyukai