Bits and Bytes
Bits and Bytes
What is data?
Data are the facts and statistics collected
together for reference or analysis
Data is information such as facts and
numbers used to analyze something or
make decisions
Computer data is information in a form that
can be processed by a computer
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
What is information?
The facts provided or learned about something
or someone
What is conveyed or represented by a particular
arrangement or sequence of things
Knowledge obtained from investigation, study, or
instruction
A collection of facts or details that provide
context and relevance, allowing individuals to
understand, analyze, and act upon a specific
situation or topic
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
What’s a bit?
A bit represents one 2-way decision or a choice
out of two possibilities
yes / no, true / false, on / off, up / down, north / south,
...
The abstraction of all of these is represented as
0 or 1
enough to tell which of TWO possibilities has been
chosen
a single digit with one of two values
hence "binary digit“
hence bit
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
To summarize
Bit - binary digit, the smallest unit of
storage (like an atom)
A bit stores just a 0 or 1
"Computer is all 0's and 1's" ... bits
Anything with two separate states can store 1
bit
Chip uses electricity 0/1 states
Hard drive uses spots North/South magnetism
0/1 states
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Bytes
Bit too small to be much use
Group 8 bits into a byte (1 Byte = 8 Bits)
One byte = grouping of 8 bits
e.g. 0 1 0 1 1 0 1 0
One byte can store one letter, e.g. 'b' or 'x‘
Bits
In general: add 1 bit, double the number of
patterns
1 bit – 2 patterns 5 bits – 32
2 bits – 4 6 bits – 64
3 bits – 8 7 bits – 128
4 bits – 16 8 bits – 256
Mathematically: n bits yields 2ⁿ patterns (2 to
the nth power)
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
SI vs. IEC
Standard SI (International System of Units) vs.
IEC (International Electrotechnical Commission)
representation
Hard disk manufacturers use standard SI
notation
1МB = 1.000.000 B / 80GB = 80.000.000.000 B
Windows uses IEC notation
The capacity of 80GB disk is presented as 74,56 GB
250 GB is presented as 232 GB
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Kibibyte, Мebibyte...
1 kibibyte (KiB) = 1.024 bytes
1 kilobyte (KB) = 1.000 bytes
1 mebibyte (MiB) = 1.048.576 byte
1 megabyte (MB) = 1.000.000 bytes
1 gibibyte (GiB) = 1.073.741.824 bytes
1 gigabyte (GB) = 1.000.000.000 bytes
1 tebibyte (TiB) = 1.099.511.627.776 bytes
1 terabyte (TB) = 1.000.000.000.000 bytes
Kilobyte or KB
One kilobyte (KB) is a
collection of about
1000 bytes. A page of
ordinary roman
alphabetic text takes
about 2 kilobytes to
store (about one byte
per letter). A typical
short email would
also take up just 1 or
2 kilobytes.
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Megabyte or MB (1)
One old 3½ “ floppy holds 1,44 Megabytes. It
can store one small book
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Megabyte or MB (2)
100 MB can store several volumes of an
encyclopedia
650 MB is the capacity of one CD-ROM
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Gigabyte or GB
1 GB holds almost two CD-ROMs
1 GB can store several shelves of books
100 GB is sufficient for a home library
ChatGPT was trained using databases from the
internet that included a massive 570 GB of data
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Terabyte or TB
3,6 million images, 300 KB each, or 300
hours of video of good quality
1.000 copies of Encyclopedia Britannica
In April 2011, U.S. Library of Congress
collected data with a capacity of 235 TB (5
TB a month)
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Petabyte or PB
In 2022, U.S. Library of Congress
managed 21 PB of digital collection
content, comprising 914 million unique
files
Google processes around 20+ PB of data
every day
The NSA processes 30+ PB of data every
day
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
3.3V
2.8V
0.5V
0.0V
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Conversions
Binary - decimal
101001112 =
1*27 + 0*26 + 1*25 + 0*24 + 0*23 + 1*22 + 1*21 + 1*20 = 16710
Decimal - binary
167/2 = 83 1
83/2 = 41 1
41/2 = 20 1
20/2 = 10 0
10/2 = 5 0
5/2 = 2 1 101001112
2/2 = 1 0
1/2 = 0 1
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Storing numbers
Integers are typically stored with either 4
or 8 bytes
2 bytes: -32768 (-215) to 32767 (215-1)
4 bytes: -2147483648 (-231) to 2147483647
(231-1)
8 bytes: -9223372036854775808 (-263) to
9223372036854775807 (263-1)
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Binary arithmetics
Adding in binary is just like normal addition with
carrying
0 +0= 0
0+1= 1
1+0= 1
1 + 1 = 10
For example:
1010 1111 + 1000 0001 = 1 0011 0000
Subtraction, multiplication, division are
analogous
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Integer overflow
When you run out of bits you can't carry
anymore
Leftmost bit indicates sign, so carrying to the
leftmost bit changes a number from positive to
negative.
So, adding 1 to 32767 goes to -32768
Similarly, adding 1 to 2147483647 goes to
-2147483648
This is called integer overflow
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Machine words
Word = group of 2, 3, 4, ... bytes
In the 1990s, computers used 32-bit
words: address space limited to 4GB
Few for demanding calculations
Modern general purpose computers and
high-end systems use 64-bit words (8B)
address space ~ 1,8 X 1019B
x86-64 machines support 48B address
space: 256 TB
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Data representations
How much data types occupy in C (in bytes)?
C Data type Typical 32-bit Intel IA32 x86-64
char 1 1 1
short 2 2 2
int 4 4 4
long 4 4 8
long long 8 8 8
float 4 4 4
double 8 8 8
long double 8 10/12 10/16
char * 4 4 8
* Or any pointer
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Printf directives:
%p: Print pointer
%x: Print Hexadecimal
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
int a = 15213;
printf("int a = 15213;\n");
show_bytes((pointer) &a, sizeof(int));
Result (Linux):
int a = 15213;
0x11ffffcb8 0x6d
0x11ffffcb9 0x3b
0x11ffffcba 0x00
0x11ffffcbb 0x00
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Representing integers
int A = 15213; Decimal: 15213
int B = -15213; Binary: 0011 1011 0110 1101
long int C = 15213;
Hex: 3 B 6 D
IA32, x86-64 A Sun A IA32 C x86-64 C Sun C
6D 00 6D 6D 00
3B 00 3B 3B 00
00 3B 00 00 3B
00 6D 00 00 6D
00
IA32, x86-64 B Sun B 00
00
93 FF
00
C4 FF
FF C4
FF 93 Two’s complement representation
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Two’s complement
Two’s complement (of a binary number):
Invertsthe digits. 0 becomes 1, 1 becomes 0 (one’s
complement).
Adds 1 (two’s complement)
Examples:
Negative numbers are represented with
their two’s complement (without the sign of
the number)
Boolean algebra
Basic logical operators:
AND . or &
OR + or |
NOT ¯ , ‘ , or (~)
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
In C
AND &&
OR ||
NOT !
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Truth tables
Example: Truth table for basic logical
operators:
AND OR NOT
X Y Z = X·Y X Y Z = X+Y X ZX
0 0 0 0 0 0 0 1
0 1 0 0 1 1 1 0
1 0 0 1 0 1
1 1 1 1 1 1
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Logic gates
In first computers, to build logic systems,
switches were opened and closed using
magnetic field and electric coils in relays
Afterwards, vacuum tubes replaced relays
Today, logic gating function and the
amplifying function are performed by
transistors
The logic is called transistor - transistor
logic (TTL)
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Performance:
X 0 0 1 1
Y 0 1 0 1
(AND) X ·Y 0 0 0 1
(OR) X+ Y 0 1 1 1
(NOT) X 1 1 0 0
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Gate latency
A standard logic gate does not respond to a change of one of its
inputs instantaneously
There is, instead, a finite delay between a change on the input and a
change on the output
The propagation delay of a standard logic gate is tG
Input
1
0 tG tG tG = 0.3 ns
Output 1
0
0 0.5 1 1.5 Time (ns)
ФАКУЛТЕТ ЗА ИНФОРМАТИЧКИ НАУКИ
И КОМПЈУТЕРСКО ИНЖЕНЕРСТВО
Boolean algebra
Created by George Boole in 1854
Algebraic structure defined over set B = {0, 1},
two binary operators (+ and ·) and one unary operation ( )
Summary
Data and information
Bits
Bytes
Binary arithmetic
Working with binary data
Implementation of binary data