Professional Documents
Culture Documents
Data representation
Storing information
bit can contain only two values: 0 and 1
2 bits can contain four values: 00, 01, 10, 11
and so on:
0000 0100 is 4
1000 0100 is -4
1000 0000 and 0000 0000 and they are not equal!
0000 0100 - 4
11100000 - -32
11010001 - -47
It store 256 numbers, from -128 to 127
Two's complementary way
There are several ways of converting negative decimal number into binary form:
1) -128 64 32 16 8 4 2 1
1 1 0 1 1 0 1 0
-128+64+16+8+2= -38
-128 64 32 16 8 4 2 1
1 1 1 1 1 0 1 0
-128+64+32+16+8+2=-6
Two's complementary way
2)For instance, we want to convert -34 into binary form. To do it we need to
identify binary form of +34.
128 64 32 16 8 4 2 1
0 0 1 0 0 0 1 0
Then we should replace all zeros with ones and all ones with zeros.
128 64 32 16 8 4 2 1
1 1 0 1 1 1 0 1
+ 1101 1101
Then we should add 1 bit to gotten binary number: 0000 0001 Answer:1101 1110
1101 1110
Two's complementary way
3)For instance, we want to convert -34 into binary form. To do it we need to
identify binary form of +34.
128 64 32 16 8 4 2 1
0 0 1 0 0 0 1 0
Then we should write all bits as they appear from right side till the first
occurrence of one(included). Then all the other bits as in previous approach
should be inverted.
0 0 1 0 0 0 1 0
1 1 0 1 1 1 1 0 Answer:1101 1110
Howto represent real numbers inbinary
(11.1875 )10 =(?.?)2
(11)10 =(1011)2
(.1875)10 =(.?)2
A = 65 = 01000001
z = 123 = 01111011
Problem: Howto store non-English characters
Early approach: every alphabet used it's own encodings.
Problem: How to store text that contains letters from different alphabets
Different encodings
Windows-1250 for Central European languages that use Latin script, (Polish,
Czech, Slovak, Hungarian, Slovene, Serbian, Croatian, Romanian and Albanian)
Windows-1251 for Cyrillic alphabets
Windows-1252 for Western languages
Windows-1253 for Greek
Windows-1254 for Turkish
Windows-1255 for Hebrew
and etc.
Problem: World alphabets
There are many alphabets that are used in the world:
● means any file stored by UTF-8 but from symbols that are present in
ASCII, will be same as stored by UTF-8
UTF-8
a = 65 = 01000001
¢ = 11000010 10100010
欽 = 6B3D
Use Unicode symbols in Python
Put following to the first line of python code
# -*- coding: utf-8 -*-
print u“қазақша”
Images and colors
Image is a set of pixels.
This file formats are used to interchange data in web, applications and etc.
● JSON
● XML
● HTML
● CSV
XML: extensible markuplanguage
<group name=”D03”>
<student id=”332”>John Black</student>
<student id=”321”>Mike Pawn</student>
<student id=”320”>Jeremy King</student>
</group>
JSON: javascript object notation
[ { name: “A04”,
students:
[ {id:”332”,name:“John Black”},
{id:”322”,name:“Jeremy King”} ]
},{ name: “B04”,
students:
[ {id:”332”,name:“John Black”},
{id:”322”,name:“Jeremy King”} ]
}
]
CSV
Tabular data saved in CSV format
name,surname,group
steve,jobs,A03
michael,phelps,B03
<html>
<body>
<h1>Header</h1>
</body>
</html>
HTML
<p>Paragraph</p>
<h1>Header</h1>
<img src="1.jpg"/>
<ul><li>Item</li><li>Item</li><li>Item</li></ul>
<a href="1.html">Link to item</a>
Browsers
Web browsers retrieve data (mostly HTML code) from server and displays it on
screen
Nowadays browsers are free, but before people had to buy browsers
History of browser
1990 - World Wide Web browser (later renamed to Nexus)
1996 - Opera