0% found this document useful (0 votes)
35 views62 pages

Understanding Numbering Systems and Arithmetic

This document discusses how computers represent and process different types of data internally. It begins by explaining that computers use binary numbering to represent all data as sequences of 0s and 1s. It then covers binary numbering systems and how decimal, binary, octal, and hexadecimal conversions work. The document also discusses binary arithmetic operations like addition and subtraction. Finally, it mentions other data types like text, audio, images and instructions that computers process.

Uploaded by

gormberkay
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)
35 views62 pages

Understanding Numbering Systems and Arithmetic

This document discusses how computers represent and process different types of data internally. It begins by explaining that computers use binary numbering to represent all data as sequences of 0s and 1s. It then covers binary numbering systems and how decimal, binary, octal, and hexadecimal conversions work. The document also discusses binary arithmetic operations like addition and subtraction. Finally, it mentions other data types like text, audio, images and instructions that computers process.

Uploaded by

gormberkay
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

TOPIC 2

Representation of Information

Departamento de Digitalización
CONTENTS
• Introduction
• Numbering Systems
– Binary System
– Conversions
– Binary arithmetic
– Other numeral systems
• Computer arithmetic
– Concept of ‘word’
– Fixed and floating point arithmetic
– IEEE-754 standardization
– IEEE-754 arithmetic
• Other data types :
– text, audio, image, instructions
Departamento de Digitalización
INTRODUCTION
• A computer is a machine that processes a set of
instructions that are executed on a set of data.

• The expression 'computer science' (also 'informatics') was


originally used in the French language (informatique) and
is formed by the contraction of the words INFORmation
and autoMATICS.

• Data and instructions are usually supplied to


machines by humans.

Departamento de Digitalización
INTRODUCTION
• Humans supplies information to machines by
means of symbols (characters) :
– Alphabetic characters: { a,b,...,z,A,B,...,Z }.

– Numeric characters: { 0,1,...,9 }.

– Special characters and graphics: { (, ) ,*,+,-, ?, ..., €,


,♣,♠,β, … }.

– Control characters: { end of line , sync character, page


forward, beep, ... }.

• … or directly by an input device, that converts


those characteres to binary.
Departamento de Digitalización
INTRODUCTION
• Computers usually represent arithmetic operations using a
representation based on the base 2 (natural binary, or plain
binary) numbering system.
– Base 8 (octal) and 16 (hexadecimal) numbering systems are also used
to obtain intermediate codes.

• Internally transforming real-life (analog) data into binary


representations that the machine is capable of processing.
– This is done constantly with the mouse, keyboard, microphone, video
capture card, etc.

• It is very important the correct storage and computation of


numerical values, because in the computer, internally,
EVERYTHING is a number (binary).

Departamento de Digitalización
NUMBERING SYSTEMS
• Numbering systems are the different ways of
representing numerical information.

• They are named referring to the base, which


represents the number of different digits to
represent all the numbers.
– A base b numbering system uses an alphabet composed of
b symbols or digits to represent the numbers. The value
that each digit provides depends on the digit itself and its
position.

• The usual numbering system for people is Decimal


(base = 10).

Departamento de Digitalización
NUMBERING SYSTEMS
Decimal representation system
• System in base 10  b=10.

• Each position has a specific name and weight :


– Position 0, weight b0=1, units.
– Position 1, weight b1=10, tens.
– Position 2, weight b2=100, hundreds.
– Position 3, weight b3=1000, thousands.
– …

Thus, 427 = 4·102+2·101+7·100 = 400 + 20 + 7.

Departamento de Digitalización
NUMBERING SYSTEMS
• For any given base, the representation of a
number N in the base b:
N  ...n3n2n1n0n1n2n3...
is an abbreviated form of representing its value :
N  ...n  b3  n  b 2  n  b1  n  b 0  n  b1  n  b2  n  b3...
3 2 1 0 1 2 3

• Most common numbering systems :


Designation Base Symbols (digits)
Decimal b = 10 S10={0,1,2,3,4,5,6,7,8,9}
Binary b=2 S2={0,1}
Octal b=8 S8={0,1,2,3,4,5,6,7}
Hexadecimal b = 16 S16={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
Departamento de Digitalización
BINARY SYSTEM
• To represent the state of the internal digital circuits that
compose the computers we use two digits (0 and 1).

• These values conceptually represented by zero [0] and


one [1] can correspond for example with :
• Two voltage levels (0 y 3,5 V.).
• Two current values (0 y 16 mA.).
• Two magnetization states (N y S).
• Two situations of a light emitter (off and on).

• Each of these ‘0’ or ‘1’ is called a bit (contraction of ‘binary


digit’).

Departamento de Digitalización
BINARY SYSTEM
• The encoding of information in binary generates large
amounts of bit patterns.
• To measure the amount of information represented in
binary, multiples are used which, unlike other physical
quantities, use the multiplier factor 1024 instead of
1000, because it is the closest multiple of 2 to the latter
(210 = 1024).
• Originally, the SI prefixes were used: Kilo, Mega, Giga,
Tera... which are based on powers of 10.
– To differentiate them, in 1999 the IEEE association defined the
names Kibi (Ki), Mebi (Mi), Gibi (Gi)... to refer to this type of
multiples in base 2.

Departamento de Digitalización
BINARY SYSTEM
The byte (eight bits) is another of the basic units of measurement of the
information represented by this system.

Multiple Represents
Nibble Set of 4 bits 1001
Byte Set of 8 bits 10101010
Kibibyte (KiB) 1024 bytes 210 * 8 bits
Mebibyte (MiB) 1024 KiB 220 * 8 bits
Gibibyte (GiB) 1024 MiB 230 * 8 bits
Tebibyte (TiB) 1024 GiB 240 * 8 bits
Pebibyte (PiB) 1024 TiB 250 * 8 bits
Exbibyte (EiB) 1024 PiB 260 * 8 bits
Zetbibyte (ZiB) 1024 EiB 270 * 8 bits
Yotbibyte (YiB) 1024 ZiB 280 * 8 bits

Departamento de Digitalización
CONVERSIONS

• Decimal to Binary
Integer part : we must divide (first)
the number (and then the resulting
quotient, until it is zero) by 2, being
the remainder of each of the divisions
read from right to left that will
compose the binary number.
Fractional part : we multiply by the
base part always with the resulting
fractional part
– 26.6)10  11010.1001…)2

Departamento de Digitalización
CONVERSIONS
• Binary to Decimal: We multiply each digit of the
binary by 2 raised to a power that will decrease
until it reaches zero.
• To determine the first power we count the
digits of the binary (5 in the example below)
and decrease that number by 1 unit (4 in the
example).

Departamento de Digitalización
BINARY ARITHMETIC
• Addition is similar to the decimal one, except
that only two digits (0 and 1) are handled.
• Basic sums :
– 0+0=0
– 0 + 1 =1
– 1 + 0 =1
– 1 + 1 = 10 (2 in binary)  “we write ‘0' and
take 1”
• Example: 100110101 + 11010101 =

Departamento de Digitalización
BINARY ARITHMETIC
• Basic substractions :
– 0-0=0
– 0 - 1 = 1  “se pone un 1 y me llevo 1”
– 1 - 0 =1
1011011
– 1 - 1 =0 - 0101110
------------
0101101

• In binary, subtraction can be done by addition (using c2,


which we will cover later) saving processor circuitry.
Therefore, we will use the addition only.

http://platea.pntic.mec.es/~lgonzale/tic/binarios/aritmetica.html

Departamento de Digitalización
Exercises

• Exercise 1: • Exercise 2:
– Convert to binary: – Find out how many
191, 25, 67, 99, 135, numbers can be
276, 45, 65 represented with 8,
10, 10, 16 and 32
25.43 bits and what is the
largest number that
73.16 can be written in
each case.

Departamento de Digitalización
Exercises

• Exercise 3: • Exercise 4:
– Given two binary – Convert to decimal :
numbers: 01001000 1100, 10101, 110111,
and 01000100 111000, 010101,
– Which of them is the 101010, 1111110
larger? Can you
compare them
without converting
them to the decimal
system?

Departamento de Digitalización
OTHER NUMERAL SYSTEMS
• They make programming easier for humans:
– working in binary is very laborious.
– It can lead to errors due to any change in the sequence of
zeros and ones.

• They are based on the ease of transforming a number


in base two to another base two to another larger
base that is also a power of two.
• Each digit of the new base will be immediately
translated into a specific sequence of 0's and 1's, and
will be used to express ourselves in abbreviated form.
• There are two main types of intermediate codes:
– Octal (Base 8)
– Hexadecimal (Base 16).

Departamento de Digitalización
OTHER NUMERAL SYSTEMS
Octal
– Digits = {0,1,2,...,7}.
– One octal digit for every three binary digits.

• Convert from binary to octal :


– Given a number N, in binary, we divide it into groups of
three values (starting from the right in the integer part, or
from the left in the fractional part).
– In the last group of three, we fill with zeros (if necessary) to
form a triplet, to the left (integer part) or right (fractional
part).

– Example:
• N=10110010,11100001(2 =
• 010 [2] 110 [6] 010 [2] , 111 [7] 000 [0] 010 [2] (2 =
• 262,702(8
Departamento de Digitalización
OTHER NUMERAL SYSTEMS
• Convert from octal to binary :
– This is done in reverse : Each octal digit is replaced
by three binary digits.
– Example: N = 376,3(8 = 011 111 110 , 011 (2
Decimal Binary Octal

0 000 0

1 001 1

2 010 2

3 011 3

4 100 4

5 101 5

6 110 6

7 111 7

Departamento de Digitalización
OTHER NUMERAL SYSTEMS

• Convert from octal to decimal:


– The conversion formula is used
– N = 376,3(8 = 3·82 + 7·81 + 6·80 + 3·8-1 = 254,375(10

• Convert from decimal to octal:


– It is done in the same way as when going from
decimal to binary but dividing and multiplying
now by the base B=8

Universidad de Burgos
Departamento
– Área de Lenguajes
de Digitalización
y Sistemas Informáticos
OTHER NUMERAL SYSTEMS
Decimal Binary Hexadecimal

Hexadecimal 0 0000 0
1 0001 1
– digits {0,…,9,A,…,F} 2 0010 2
• Conversion from binary to 3 0011 3
4 0100 4
hexadecimal: we divide the number
5 0101 5
into groups of four digits, starting 6 0110 6

from the right (integer part), or from 7 0111 7


8 1000 8
the left (fractional part). 9 1001 9
10 1010 A
11 1011 B
• The rest of the conversions are 12 1100 C

carried out analogously to the octal 13 1101 D


14 1110 E
and binary base. 15
32
1111 F
Departamento de Digitalización
Exercises

• Exercise 5: • Exercise 6:
– Convert to octal: – Convert to decimal :
– 37) 10, 63)10, 513)10, – 45)8, 125)8, 625)8
119)10

Departamento de Digitalización
Exercises

• Exercise 7: • Exercise 8:
– Convert to decimal : – Convert to
– 2BC5)16, 100)16, hexadecimal :
1FF)16 – 3519)10, 1024)10,
4095)10

Departamento de Digitalización
Exercises

• Exercise 9: • Exercise 10:


– Convert to octal : – Convert to binary :
– 1101101)2, 101110)2, – 25)8, 372)8, 2753)8
11011011)2,
101101011)2

Departamento de Digitalización
Exercises

• Exercise 11: • Exercise 12:


– Convert to – Convert to binary :
hexadecimal : – 7A5D)16, 1010)16,
– 10101001010111010 8F8F)16
10)2,
111000011110000)2,
1010000111010111)2

Departamento de Digitalización
CONCEPT OF ‘WORD’
• “A word is a finite string of bits that are handled as
a set by the machine”.

• The size or length of a word refers to the number


of bits contained in it.

• It is a very important aspect when designing a


computer architecture.

• Modern computers typically have a word size of


32 or 64 bits.
Departamento de Digitalización
CONCEPT OF ‘WORD’
Words can be used for :

• Numerical representation
– Fixed point arithmetic: Integers.
– Floating point arithmetic: Real numbers.

• Memory addresses
– Data is in the computer's memory.
– An address must be given to access a particular
piece of data.

Departamento de Digitalización
CONCEPT OF ‘WORD’
• Memory-to-processor transfer
– When the processor reads or writes from the memory
subsystem, the amount of data transferred is often one word.
• Instructions
– Machine instructions are usually fractions or multiples of the
word length of the architecture.
– This is a natural choice since instructions and data usually share
the same memory subsystem.

In the end, it's all about words (bit strings) in a computer!

Departamento de Digitalización
COMPUTER ARITHMETIC
• Computers do not store numbers with infinite
precision but in an approximate form using a
fixed number of bit  Words

• The programmer can choose between several


representations or 'data types'.

• The data types may differ in the number of bits


used and how the represented number is stored :
– Fixed comma or fixed point (also called 'integer').
– Floating comma or floating point (real numbers).

Departamento de Digitalización
FIXED POINT ARITHMETIC
• An integer can be represented using all the bits
of a computer word.

• We will consider 3 types of representation :


– Pure binary
– Sign and magnitude
– 1's complement and 2's complement

Departamento de Digitalización
FIXED POINT ARITHMETIC
Sign and magnitude

• One bit is reserved for the sign.


• On a machine with a word length of 32 bits, the integers are
between –231 - 1 y +231 -1
* +0 y -0 represent the same number.

Departamento de Digitalización
FIXED POINT ARITHMETIC
1’s Complement (C1)

• 1’s complement is the inversion of a binary number.


• t is calculated by subtracting the magnitude of the number
from the "all ones" binary number of equal bit length (C1).
Example: C1 of 46)10 = 101110)2
111111
-101110
------------
010001
• In a simpler way :
– All bits are changed from '0' to '1' and from '1' to '0‘

This can be done only if the number is negative (the sign


bit is set to '1').
Departamento de Digitalización
FIXED POINT ARITHMETIC
2’s Complement (C2)

• 2's complement is an efficient way to represent negative


numbers for binary subtraction.
• It is calculated by adding 1 to the 1's complement (C1) of the
number.
010001
– 46)10 = 101110)2  010001)C1 + 1
------------
010010

• Steps to be performed (only if the number is negative):


– Change all bits from '0' to '1' and from '1' to '0‘
– Add 1

Departamento de Digitalización
FIXED POINT ARITHMETIC
Decimal Unsigned Sign and mag. 2’s compl.
7 111 - -
6 110 - -
5 101 - -
4 100 - -
3 011 011 011
2 010 010 010
1 001 001 001
+0 000 000 000
-0 - 000 000
-1 - 101 111
-2 - 110 110
-3 - 111 101
-4 - - 100
Departamento de Digitalización
FIXED POINT ARITHMETIC
• A number represented in integer format is 'exact'.

• Arithmetic operations between integers are also 'exact' as


long as :
– The solution is not outside the range that can be represented (usually
signed).
– In these cases it is said that an overflow or underflow error is
committed.
– In the division, any remainder is disregarded.

Departamento de Digitalización
Exercises

• Exercise 13: • Exercise 14:


– Represents in all fixed- – What would be the
point formats the integer decimal numbers
following numbers, corresponding to the
numbers
indicating the word • 1010 11110
length required in each • 00111 1011
• 11000 0010
case:
– 22, Using these representations :
a) Unsigned (pure binary)
– 255, b) Sign and magnitude
– -31 c) 1’s Complement
d) 2’s Complement
– 0
– -3675

Departamento de Digitalización
FLOATING POINT ARITHMETIC
• It is done using standardized scientific notation.
– 0.000000001 = 1.0 × 10-9
– 3155760000 = 3.15576 × 109

• En informática se utiliza siempre la base 2 :


– In computing, base 2 is always used, and there is usually
only one null digit to the left of the point.
– 0.xxxx × 2yyyy

– It is only necessary to store the q (mantissa or


significand) and m (exponent) fields.
52

Departamento de Digitalización
FLOATING POINT ARITHMETIC
• La coma flotante no es una representación exacta para
reales, sino que únicamente permite representar los números
en forma aproximada.
– Es preciso aplicar cuidadosamente técnicas de redondeo.
– En los programas no se debe testear la igualdad estricta de dos
números en coma flotante.

• La realización de operaciones con datos en coma flotante es


compleja: circuitos específicos dedicados.
– Los computadores de baja potencia trabajaban en coma flotante
mediante software.
– A partir del Intel 8086 → coprocesadores de coma flotante.
– Actualmente los coprocesadores de coma flotante se integran en el
chip del microprocesador. 53

Departamento de Digitalización
FLOATING POINT ARITHMETIC
Normalization IEEE-754

• Simple precision (32 bits)

– Sign (1 bit): 0 = positive; 1 = negative.


– Mantissa/significand : 23 bits.
– Exponent (8 bits).

• Double precision (64 bits)


– Sign (1 bit): 0 = positive; 1 = negative.
– Mantisa (52 bits).
– Exponent (11 bits).

Departamento de Digitalización
OTHER DATA TYPES
Text

• Transformations from characters (alphabet or symbol sets)


to bit patterns is by means of I/O codes. Character types :

– Alphabetic (A, B, C, …, X, Y, Z, a, ,b, c, …, x, y, z).


– Numeric (0-9).
– Special: orthographic and mathematical symbols (+, -, [, …).
– Geometric and graphic (|, ⌐, ╒, ║, ╓, ╔, ╕, …).
– Control characters: they represent control commands (NL, BEL, etc.).

 How do we represent the text? The idea is simple, to each


character of the alphabet is associated a bit pattern → it is
encoded.

Departamento de Digitalización
OTHER DATA TYPES
Text

• There are some coding standards :


– EBCDIC (IBM) [deprecated]
– ASCII (original and extended)
– UNICODE (UTF-8)
– ISO 8859

• All of them use 8 bits to represent each character


(except UNICODE, which uses 16)

Departamento de Digitalización
OTHER DATA TYPES
Text
Original ASCII table (7 bits)

Departamento de Digitalización
OTHER DATA TYPES
Text
ISO 8859 standardization family (ASCII extensions)

Español

Departamento de Digitalización
OTHER DATA TYPES
Text

• Disadvantages of the previous codes (especially on the


Internet) :
1. The encoded symbols are insufficient to represent the special characters
required by many applications.
2. The symbols and codes added in the 8-bit versions are not standardized.
3. They are based on Latin characters, while other cultures use very
different symbols.

• Unicode (ISO/IEC 10646) is proposed by a consortium of


companies and entities that tries to make it possible to write
applications that are able to process text from many
different cultures.
– If Latin characters are not enough, more bits are used to represent characters
from other cultures (ideograms).
– The UNICODE table uses 16 bits

Departamento de Digitalización
OTHER DATA TYPES
Audio
• It is picked up by a microphone that produces an analog signal (a signal
that can take any value within a certain continuous interval).

• Sounds or audio signals are picked up by a sensor (e.g. a microphone)


which transforms them into analog electrical signals. These signals are
amplified to fit within certain limit values.

Departamento de Digitalización
OTHER DATA TYPES
Audio

• Sampling is then carried out to discretize that signal, and subsequently


digitize/encode it. There are two fundamental parameters in sampling:
frequency and number of bits (precision).
• Samples are stored as integer numbers.

Departamento de Digitalización
OTHER DATA TYPES
Audio

• The higher the frequency → the more faithful the sampled signal is to the
real signal.

Departamento de Digitalización
OTHER DATA TYPES
Audio
The frequency at which the measurement is made is the
sampling rate :
– Human Ear: up to 20,000 Hz
– Computer: double the maximum frequency: up to 48,000 Hz
– Accuracy (1x8 bits mono ~ 2x16 bits stereo).

Example: Compact Disc


– Sampling rate/frequency: 44100 Hz.
– 16-bit samples and with two channels (stereo): 44100×2×2 = 172 Kb, to
represent one second of sound.
– An audio CD can contain 10 Mb per minute and more than 600 Mb in one
hour.

Departamento de Digitalización
OTHER DATA TYPES
Audio

Other ways of encoding audio: the "electronic score


(MIDI).

• 16 bits to represent the note, instrument, volume, etc.


• Split the time axis into equal parts (1/100 sec.)
• Different instruments → multiple tracks.
• One second of sound with four tracks would take up :
100×2×4 = 800 bytes

Departamento de Digitalización
OTHER DATA TYPES
Audio

• To perform the conversion from analog to digital and vice


versa, a circuit (or software) called CODEC
(COdifier/DECoder) is used.

• Examples of CODECS are :


– PCM (Pulse Code Modification),
– DPCM (Differential Pulse Code Modification), ADPCM (Adaptive DPCM),
– MPEG Audio Capa-II (para formatos MP2, MP3 y AAC)
– and other proprietary formats.

• ompilation process to produce a “binary sound" file : .wav,


.mid, .mp3, .aiff, …
Departamento de Digitalización
OTHER DATA TYPES
Image

 Let's consider as an image a two-


dimensional visual representation of
some object or set of objects.

 When we store these images


inside a computer it is necessary
to convert them into zeros and
ones (bits).

 There are two methods :


 Bitmaps: JPG, PNG, GIF …
 Vector images: SVG, PDF, DXF …

Departamento de Digitalización
OTHER DATA TYPES
Image

Pixel images
 The image is considered to be divided into a grid of cells or picture elements
(pixels).
 Each image element is encoded: a value corresponding to its gray level (black
and white images) or color is associated with it.

 Resolution (pixel amount) is


the number of horizontal
elements times the number of
vertical elements.

81

Departamento de Digitalización
OTHER DATA TYPES
Image

PIXEL

 Pixel or picture element is the


smallest element in a digital image
that can be controlled.

 The value of the pixel determines


how it will appear in the image :

o In a black and white image it takes a


single value indicating its intensity

o In a color image it takes 3 or 4 values


indicating color and transparency, if
any.

Departamento de Digitalización
OTHER DATA TYPES
Image

• Resolution of an image: pixels per inch.


– Grayscale: 1 byte per pixel.
– RGB/CMY: If for each color we use a number of 8 bits, we will have a total of
24 bits per pixel which gives 224 = 16777216 colors

• Reduce the size of the image. Use of custom color palette :


– Number the colors: for example: (0, black), (1, blue), (2, white) ...
– Encode colors with a number of bits (8 ~ 16)
– Each pixel is represented by this color.
– Information about the palette must be stored!
– Example: GIF format

Departamento de Digitalización
OTHER DATA TYPES
Image

• How cameras capture pixel images • Matrix sensor. Main technologies: CCD
and CMOS

• Light is captured in different


wavelengths, the colors are assigned
artificially.

Departamento de Digitalización
OTHER DATA TYPES
Image
Vector images

 Mathematical formulas of lines,


points and curves are used to
represent the image.

 They take up much less space


than bitmaps.

 These images can be enlarged


without losing image quality.
You just need to reevaluate the
mathematical equations.

85

Departamento de Digitalización
OTHER DATA TYPES
Image

Image representation formats (bit maps or pixels)

Departamento de Digitalización
OTHER DATA TYPES
Image

Image representation formats (vector maps)

Departamento de Digitalización
OTHER DATA TYPES
Instructions

• Representation of instructions: in assembly language or high-level


language, they are given in text form.
How do we explain our algorithm to the computer

The computer can only work with 0's and 1's.

The instructions must be sequences of 0's and 1's


(the same as data)

This primary language is called machine code and is the only one
understandable by the CPU of the computer.

Departamento de Digitalización
Exercises

• Exercise 15: • Exercise 16:


– How many MiB does – How much (KiB) would a
10 seconds of PCM BMP image of 640x480
audio at 44.1KHz and pixels with 16 bits per
8bits/sample take up? color take up?

Departamento de Digitalización
BIBLIOGRAPHY
• Estructura y diseño de computadores
David A. Patterson, John L. Hennesy, Reverté, 2000

• Introducción a la Informática
Alberto Prieto, Antonio Lloris y Juan Carlos Torres (2006), McGraw Hill, ISBN
8448146247

• Introducción a la Informática
Miles J. Murdocca, Vincent P. Heuring, Pearson Education, 2002

• Conceptos de Informática
Alberto Prieto y Beatriz Prieto (2005). Schaum, ISBN 8448198572

Departamento de Digitalización

You might also like