SlideShare a Scribd company logo
Numeral Systems
Binary, Decimal and Hexadecimal Numbers
Svetlin Nakov
Telerik Corporation
www.telerik.com
Table of Contents
1. Numerals Systems
Binary and Decimal Numbers
Hexadecimal Numbers
Conversion between Numeral Systems
3. Representation of Numbers
Positive and Negative Integer Numbers
Floating-Point Numbers
4. Text Representation
2
Numeral Systems
Conversion between Numeral Systems
Decimal numbers (base 10)
Represented using 10 numerals:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Each position represents a power of 10:
401 = 4*102 + 0*101 + 1*100 = 400 + 1
130 = 1*102 + 3*101 + 0*100 = 100 + 30
9786 = 9*103 + 7*102 + 8*101 + 6*100 =
= 9*1000 + 7*100 + 8*10 + 6*1
Decimal Numbers
4
Binary Numeral System
5
1 0 1 1 0 0 1 01 0 0 1 0 0 1 01 0 0 1 0 0 1 11 1 1 1 1 1 1 1
Binary numbers are represented by sequence
of bits (smallest unit of information – 0 or 1)
 Bits are easy to represent in electronics
Binary numbers (base 2)
Represented by 2 numerals: 0 and 1
Each position represents a power of 2:
 101b = 1*22 + 0*21 + 1*20 = 100b + 1b = 4 + 1 =
= 5
 110b = 1*22 + 1*21 + 0*20 = 100b + 10b = 4 + 2 =
= 6
 110101b = 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20 =
= 32 + 16 + 4 + 1 =
= 53
Binary Numbers
6
Binary to Decimal Conversion
Multiply each numeral by its exponent:
 1001b = 1*23 + 1*20 = 1*8 + 1*1 =
= 9
 0111b = 0*23 + 1*22 + 1*21 + 1*20 =
= 100b + 10b + 1b = 4 + 2 + 1 =
= 7
 110110b = 1*25 + 1*24 + 0*23 + 1*22 + 1*21 =
= 100000b + 10000b + 100b + 10b =
= 32 + 16 + 4 + 2 =
= 54
7
Decimal to Binary Conversion
Divide by 2 and append the reminders in
reversed order:
500/2 = 250 (0)
250/2 = 125 (0)
125/2 = 62 (1)
62/2 = 31 (0) 500d = 111110100b
31/2 = 15 (1)
15/2 = 7 (1)
7/2 = 3 (1)
3/2 = 1 (1)
1/2 = 0 (1)
8
Hexadecimal Numbers
Hexadecimal numbers (base 16)
 Represented using 16 numerals:
0, 1, 2, ... 9, A, B, C, D, E and F
Usually prefixed with 0x
0  0x0 8  0x8
1  0x1 9  0x9
2  0x2 10  0xA
3  0x3 11  0xB
4  0x4 12  0xC
5  0x5 13  0xD
6  0x6 14  0xE
7  0x7 15  0xF
9
Hexadecimal Numbers (2)
Each position represents a power of 16:
 9786hex = 9*163 + 7*162 + 8*161 + 6*160 =
= 9*4096 + 7*256 + 8*16 + 6*1 =
= 38790
 0xABCDEFhex = 10*165 + 11*164 + 12*163 +
13*162 + 14*161 + 15*160 =
= 11259375
10
Hexadecimal to Decimal
Conversion
Multiply each digit by its exponent
 1F4hex = 1*162 + 15*161 + 4*160 =
= 1*256 + 15*16 + 4*1 =
= 500d
 FFhex = 15*161 + 15*160 =
= 240 + 15 =
= 255d
11
Decimal to Hexadecimal
Conversion
Divide by 16 and append the reminders in
reversed order
500/16 = 31 (4)
31/16 = 1 (F) 500d = 1F4hex
1/16 = 0 (1)
12
Binary to Hexadecimal
(and Back) Conversion
The conversion from binary to hexadecimal
(and back) is straightforward: each hex digit
corresponds to a sequence of 4 binary digits:
0x0 = 0000 0x8 = 1000
0x1 = 0001 0x9 = 1001
0x2 = 0010 0xA = 1010
0x3 = 0011 0xB = 1011
0x4 = 0100 0xC = 1100
0x5 = 0101 0xD = 1101
0x6 = 0110 0xE = 1110
0x7 = 0111 0xF = 1111
13
Numbers Representation
Positive and Negative Integers and
Floating-Point Numbers
Representation of Integers
A short is represented by 16 bits
100 = 26 + 25 + 22 =
= 00000000 01100100
An int is represented by 32 bits
65545 = 216 + 23 + 20 =
= 00000000 00000001 00000000 00001001
A char is represented by 16 bits
‘0’ = 48 = 25 + 24 =
= 00000000 00110000
15
Positive and Negative Numbers
A number's sign is determined by the
Most Significant Bit (MSB)
Only in signed integers: sbyte, short, int, long
Leading 0 means positive number
 Leading 1 means negative number
Example: (8 bit numbers)
0XXXXXXXb > 0 e.g. 00010010b = 18
00000000b = 0
1XXXXXXXb < 0 e.g. 10010010b = -110
16
Positive and Negative Numbers (2)
The largest positive 8-bit sbyte number is:
127 (27 - 1) = 01111111b
The smallest negative 8-bit number is:
-128 (-27) = 10000000b
The largest positive 32-bit int number is:
2 147 483 647 (231 - 1) = 01111…11111b
The smallest negative 32-bit number is:
-2 147 483 648 (-231) = 10000…00000b
17
Representation of 8-bit Numbers
+127 = 01111111
...
+3 = 00000011
+2 = 00000010
+1 = 00000001
+0 = 00000000
-1 = 11111111
-2 = 11111110
-3 = 11111101
...
-127 = 10000001
-128 = 10000000
Positive 8-bit numbers have the
format 0XXXXXXX
Their value is the decimal of
their last 7 bits (XXXXXXX)
Negative 8-bit numbers have
the format 1YYYYYYY
Their value is 128 (27) minus (-)
the decimal of YYYYYYY
10010010b = 27 – 10010b =
= 128 - 18 = -110
18
Floating-Point Numbers
Floating-point numbers representation
(according to the IEEE 754 standard*):
Example:
19
2k-1 20 2-1 2-2 2-n
S P0 ... Pk-1 M0 M1 ... Mn-1
Sign Exponent Mantissa
1 10000011 01010010100000000000000
Mantissa = 1,322265625Exponent = 4Sign = -1
Bits [22…0]Bits [30…23]Bit 31
* See http://en.wikipedia.org/wiki/Floating_point
Text Representation in
Computer Systems
How Computers Represent
Text Data?
A text encoding is a system that uses binary
numbers (1 and 0) to represent characters
 Letters, numerals, etc.
In the ASCII encoding each character consists
of 8 bits (one byte) of data
ASCII is used in nearly all personal computers
In the Unicode encoding each character
consists of 16 bits (two bytes) of data
Can represent many alphabets
21
Character Codes – ASCIITable
Excerpt
from the
ASCII
table
Binary
Code
Decimal
Code
Character
01000001 65 A
01000010 66 B
01000011 67 C
01000100 68 D
00100011 35 #
01100000 48 0
00110001 49 1
01111110 126 ~
22
Strings of Characters
Strings are sequences of characters
Null-terminated (like in C)
Represented by array
Characters in the strings can be:
8 bit (ASCII / windows-1251 / …)
16 bit (UTF-16)
… … … … … … … … 0
4 bytes
length … … … … … …
23
Questions?
Numeral Systems
http://academy.telerik.com
Exercises
1. Write a program to convert decimal numbers to their
binary representation.
2. Write a program to convert binary numbers to their
decimal representation.
3. Write a program to convert decimal numbers to their
hexadecimal representation.
4. Write a program to convert hexadecimal numbers to
their decimal representation.
5. Write a program to convert hexadecimal numbers to
binary numbers (directly).
6. Write a program to convert binary numbers to
hexadecimal numbers (directly).
25
Exercises (2)
7. Write a program to convert from any numeral system
of given base s to any other numeral system of base
d (2 ≤ s, d ≤ 16).
8. Write a program that shows the binary
representation of given 16-bit signed integer number
(the C# type short).
9. * Write a program that shows the internal binary
representation of given 32-bit signed floating-point
number in IEEE 754 format (the C# type float).
Example: -27,25  sign = 1, exponent = 10000011,
mantissa = 10110100000000000000000.
26

More Related Content

What's hot

Number system
Number systemNumber system
Number systemkashee99
 
Number system
Number systemNumber system
Number systemaviban
 
Numbersystemcont
NumbersystemcontNumbersystemcont
Numbersystemcont
Sajib
 
data representation
 data representation data representation
data representation
Haroon_007
 
08. Numeral Systems
08. Numeral Systems08. Numeral Systems
08. Numeral Systems
Intro C# Book
 
Binary octal
Binary octalBinary octal
Binary octaldrdipo4
 
Representation of Signed Numbers - R.D.Sivakumar
Representation of Signed Numbers - R.D.SivakumarRepresentation of Signed Numbers - R.D.Sivakumar
Representation of Signed Numbers - R.D.Sivakumar
Sivakumar R D .
 
Data Representation
Data RepresentationData Representation
Data Representation
Education Front
 
Data representation
Data representationData representation
Data representation
shashikant pabari
 
Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)
Frankie Jones
 
Conversion of number system with base concept
Conversion of number system with base conceptConversion of number system with base concept
Conversion of number system with base concept
University of Potsdam
 
Data representation
Data representationData representation
Data representation
Kaviya Arikrishnan
 
Data Representation
Data RepresentationData Representation
Data RepresentationRick Jamil
 
Number Systems and Binary Aritmetics
Number Systems and Binary AritmeticsNumber Systems and Binary Aritmetics
Number Systems and Binary Aritmetics
Delowar Hossain
 
Number system
Number systemNumber system
Number system
Bikash Kumar
 
Decimal to binary number
Decimal to binary numberDecimal to binary number
Decimal to binary numberguestd8696a
 
Number system
Number systemNumber system
Number system
Mohit Saini
 
Understand data representation on CPU 1
Understand data representation on CPU 1Understand data representation on CPU 1
Understand data representation on CPU 1
Brenda Debra
 

What's hot (20)

Okkkkk
OkkkkkOkkkkk
Okkkkk
 
Number system
Number systemNumber system
Number system
 
Number system
Number systemNumber system
Number system
 
Numbersystemcont
NumbersystemcontNumbersystemcont
Numbersystemcont
 
data representation
 data representation data representation
data representation
 
08. Numeral Systems
08. Numeral Systems08. Numeral Systems
08. Numeral Systems
 
Binary octal
Binary octalBinary octal
Binary octal
 
Representation of Signed Numbers - R.D.Sivakumar
Representation of Signed Numbers - R.D.SivakumarRepresentation of Signed Numbers - R.D.Sivakumar
Representation of Signed Numbers - R.D.Sivakumar
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Data representation
Data representationData representation
Data representation
 
Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)Chapter 2 Data Representation on CPU (part 1)
Chapter 2 Data Representation on CPU (part 1)
 
Conversion of number system with base concept
Conversion of number system with base conceptConversion of number system with base concept
Conversion of number system with base concept
 
Data representation
Data representationData representation
Data representation
 
Chapter1b
Chapter1bChapter1b
Chapter1b
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Number Systems and Binary Aritmetics
Number Systems and Binary AritmeticsNumber Systems and Binary Aritmetics
Number Systems and Binary Aritmetics
 
Number system
Number systemNumber system
Number system
 
Decimal to binary number
Decimal to binary numberDecimal to binary number
Decimal to binary number
 
Number system
Number systemNumber system
Number system
 
Understand data representation on CPU 1
Understand data representation on CPU 1Understand data representation on CPU 1
Understand data representation on CPU 1
 

Viewers also liked

Chapter 04 computer codes
Chapter 04 computer codesChapter 04 computer codes
Chapter 04 computer codes
Hareem Aslam
 
Chapter 08 secondary storage
Chapter 08 secondary storageChapter 08 secondary storage
Chapter 08 secondary storagesumatipuri
 
Chapter 16 bdp
Chapter 16 bdpChapter 16 bdp
Chapter 16 bdp
Hareem Aslam
 
Chapter 14 os
Chapter 14 osChapter 14 os
Chapter 14 os
Hareem Aslam
 
Chapter08 internet &amp; multimedia (a)
Chapter08   internet &amp; multimedia (a)Chapter08   internet &amp; multimedia (a)
Chapter08 internet &amp; multimedia (a)
Ainuddin Yousufzai
 
Chapter 15 asp
Chapter 15 aspChapter 15 asp
Chapter 15 asp
Hareem Aslam
 
Minterm and maxterm
Minterm and maxtermMinterm and maxterm
Minterm and maxtermparsa.khan64
 
Chapter 03 number system
Chapter 03 number systemChapter 03 number system
Chapter 03 number system
Hareem Aslam
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
Hareem Aslam
 
Auditing as a profession
Auditing as a professionAuditing as a profession
Auditing as a profession
Lloyd's Register - Management Systems
 
Auditing Profession – Global Development And Key Issues
Auditing Profession – Global Development And Key IssuesAuditing Profession – Global Development And Key Issues
Auditing Profession – Global Development And Key Issues
Nik Hasyudeen
 
Computer Fundamentals Chapter 12 cl
Computer Fundamentals Chapter 12 clComputer Fundamentals Chapter 12 cl
Computer Fundamentals Chapter 12 clSaumya Sahu
 
Ascii and Unicode (Character Codes)
Ascii and Unicode (Character Codes)Ascii and Unicode (Character Codes)
Ascii and Unicode (Character Codes)
Project Student
 
Ch13
Ch13Ch13
Computer Fundamentals Chapter 07 pam
Computer Fundamentals Chapter  07 pamComputer Fundamentals Chapter  07 pam
Computer Fundamentals Chapter 07 pamSaumya Sahu
 
Ch04.soln
Ch04.solnCh04.soln
Ch04.soln
sifat775
 
Ch04
Ch04Ch04
Kieso inter ch12_ ifrs
Kieso inter ch12_ ifrsKieso inter ch12_ ifrs
Kieso inter ch12_ ifrs
waltreade
 
Computer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bcoComputer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bcoSaumya Sahu
 
Ch03
Ch03Ch03

Viewers also liked (20)

Chapter 04 computer codes
Chapter 04 computer codesChapter 04 computer codes
Chapter 04 computer codes
 
Chapter 08 secondary storage
Chapter 08 secondary storageChapter 08 secondary storage
Chapter 08 secondary storage
 
Chapter 16 bdp
Chapter 16 bdpChapter 16 bdp
Chapter 16 bdp
 
Chapter 14 os
Chapter 14 osChapter 14 os
Chapter 14 os
 
Chapter08 internet &amp; multimedia (a)
Chapter08   internet &amp; multimedia (a)Chapter08   internet &amp; multimedia (a)
Chapter08 internet &amp; multimedia (a)
 
Chapter 15 asp
Chapter 15 aspChapter 15 asp
Chapter 15 asp
 
Minterm and maxterm
Minterm and maxtermMinterm and maxterm
Minterm and maxterm
 
Chapter 03 number system
Chapter 03 number systemChapter 03 number system
Chapter 03 number system
 
Chapter 05 computer arithmetic
Chapter 05 computer arithmeticChapter 05 computer arithmetic
Chapter 05 computer arithmetic
 
Auditing as a profession
Auditing as a professionAuditing as a profession
Auditing as a profession
 
Auditing Profession – Global Development And Key Issues
Auditing Profession – Global Development And Key IssuesAuditing Profession – Global Development And Key Issues
Auditing Profession – Global Development And Key Issues
 
Computer Fundamentals Chapter 12 cl
Computer Fundamentals Chapter 12 clComputer Fundamentals Chapter 12 cl
Computer Fundamentals Chapter 12 cl
 
Ascii and Unicode (Character Codes)
Ascii and Unicode (Character Codes)Ascii and Unicode (Character Codes)
Ascii and Unicode (Character Codes)
 
Ch13
Ch13Ch13
Ch13
 
Computer Fundamentals Chapter 07 pam
Computer Fundamentals Chapter  07 pamComputer Fundamentals Chapter  07 pam
Computer Fundamentals Chapter 07 pam
 
Ch04.soln
Ch04.solnCh04.soln
Ch04.soln
 
Ch04
Ch04Ch04
Ch04
 
Kieso inter ch12_ ifrs
Kieso inter ch12_ ifrsKieso inter ch12_ ifrs
Kieso inter ch12_ ifrs
 
Computer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bcoComputer Fundamentals_Chapter 02 bco
Computer Fundamentals_Chapter 02 bco
 
Ch03
Ch03Ch03
Ch03
 

Similar to 08 Numeral systems

Chapter two FHI.pptx
Chapter two FHI.pptxChapter two FHI.pptx
Chapter two FHI.pptx
ODAATUBE1
 
Video lectures
Video lecturesVideo lectures
Video lectures
Edhole.com
 
Mba ebooks
Mba ebooksMba ebooks
Mba ebooks
Edhole.com
 
Number System.pdf
Number System.pdfNumber System.pdf
Number System.pdf
Sweta Kumari Barnwal
 
Number_Systems (2).ppt
Number_Systems (2).pptNumber_Systems (2).ppt
Number_Systems (2).ppt
nivedita murugan
 
Digital Logic Design.pptx
Digital Logic Design.pptxDigital Logic Design.pptx
Digital Logic Design.pptx
AminaZahid16
 
PPT_Module_1.pptx
PPT_Module_1.pptxPPT_Module_1.pptx
PPT_Module_1.pptx
Techie5879
 
Logic Design 2009
Logic Design 2009Logic Design 2009
Logic Design 2009
lionking
 
Digital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdfDigital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdf
Kannan Kanagaraj
 
Number System and Conversions.pptx
Number System and Conversions.pptxNumber System and Conversions.pptx
Number System and Conversions.pptx
khalidkk6
 
Number systems
Number systemsNumber systems
Number systems
pyingkodi maran
 
Data Representation
Data RepresentationData Representation
Data Representation
Education Front
 
Number Systems
Number SystemsNumber Systems
Number Systems
Infinity Tech Solutions
 
LEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptx
LEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptxLEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptx
LEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptx
Ahsan433
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
4NM21IS132SAISHARATH
 
Chapter 02 Data Types
Chapter 02   Data TypesChapter 02   Data Types
Chapter 02 Data TypesNathan Yeung
 
Cit 1101 lec 02
Cit 1101 lec 02Cit 1101 lec 02
Cit 1101 lec 02
sohag sikder
 
digitalelectronics.ppt
digitalelectronics.pptdigitalelectronics.ppt
digitalelectronics.ppt
HarshalVaidya11
 

Similar to 08 Numeral systems (20)

Chapter two FHI.pptx
Chapter two FHI.pptxChapter two FHI.pptx
Chapter two FHI.pptx
 
Video lectures
Video lecturesVideo lectures
Video lectures
 
Mba ebooks
Mba ebooksMba ebooks
Mba ebooks
 
Number System.pdf
Number System.pdfNumber System.pdf
Number System.pdf
 
Number_Systems (2).ppt
Number_Systems (2).pptNumber_Systems (2).ppt
Number_Systems (2).ppt
 
Digital Logic Design.pptx
Digital Logic Design.pptxDigital Logic Design.pptx
Digital Logic Design.pptx
 
PPT_Module_1.pptx
PPT_Module_1.pptxPPT_Module_1.pptx
PPT_Module_1.pptx
 
Lec 02
Lec 02Lec 02
Lec 02
 
Logic Design 2009
Logic Design 2009Logic Design 2009
Logic Design 2009
 
Digital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdfDigital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdf
 
Number System and Conversions.pptx
Number System and Conversions.pptxNumber System and Conversions.pptx
Number System and Conversions.pptx
 
Number systems
Number systemsNumber systems
Number systems
 
2013 1
2013 1 2013 1
2013 1
 
Data Representation
Data RepresentationData Representation
Data Representation
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
LEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptx
LEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptxLEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptx
LEfddfffhhfrrdvvggfdwfcxsfvdsfgC 02 A.pptx
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
 
Chapter 02 Data Types
Chapter 02   Data TypesChapter 02   Data Types
Chapter 02 Data Types
 
Cit 1101 lec 02
Cit 1101 lec 02Cit 1101 lec 02
Cit 1101 lec 02
 
digitalelectronics.ppt
digitalelectronics.pptdigitalelectronics.ppt
digitalelectronics.ppt
 

More from maznabili

22 Methodology of problem solving
22 Methodology of problem solving22 Methodology of problem solving
22 Methodology of problem solving
maznabili
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
maznabili
 
21 high-quality programming code construction part-i
21 high-quality programming code construction part-i21 high-quality programming code construction part-i
21 high-quality programming code construction part-i
maznabili
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principles
maznabili
 
19 Algorithms and complexity
19 Algorithms and complexity19 Algorithms and complexity
19 Algorithms and complexity
maznabili
 
18 Hash tables and sets
18 Hash tables and sets18 Hash tables and sets
18 Hash tables and sets
maznabili
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
maznabili
 
16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
maznabili
 
15 Text files
15 Text files15 Text files
15 Text files
maznabili
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classes
maznabili
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
maznabili
 
12 Exceptions handling
12 Exceptions handling12 Exceptions handling
12 Exceptions handling
maznabili
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
maznabili
 
10 Recursion
10 Recursion10 Recursion
10 Recursion
maznabili
 
09 Methods
09 Methods09 Methods
09 Methods
maznabili
 
07 Arrays
07 Arrays07 Arrays
07 Arrays
maznabili
 
06 Loops
06 Loops06 Loops
06 Loops
maznabili
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
maznabili
 
04 Console input output-
04 Console input output-04 Console input output-
04 Console input output-
maznabili
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
maznabili
 

More from maznabili (20)

22 Methodology of problem solving
22 Methodology of problem solving22 Methodology of problem solving
22 Methodology of problem solving
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
 
21 high-quality programming code construction part-i
21 high-quality programming code construction part-i21 high-quality programming code construction part-i
21 high-quality programming code construction part-i
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principles
 
19 Algorithms and complexity
19 Algorithms and complexity19 Algorithms and complexity
19 Algorithms and complexity
 
18 Hash tables and sets
18 Hash tables and sets18 Hash tables and sets
18 Hash tables and sets
 
17 Trees and graphs
17 Trees and graphs17 Trees and graphs
17 Trees and graphs
 
16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
 
15 Text files
15 Text files15 Text files
15 Text files
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classes
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
12 Exceptions handling
12 Exceptions handling12 Exceptions handling
12 Exceptions handling
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
 
10 Recursion
10 Recursion10 Recursion
10 Recursion
 
09 Methods
09 Methods09 Methods
09 Methods
 
07 Arrays
07 Arrays07 Arrays
07 Arrays
 
06 Loops
06 Loops06 Loops
06 Loops
 
05 Conditional statements
05 Conditional statements05 Conditional statements
05 Conditional statements
 
04 Console input output-
04 Console input output-04 Console input output-
04 Console input output-
 
03 Operators and expressions
03 Operators and expressions03 Operators and expressions
03 Operators and expressions
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 

08 Numeral systems

  • 1. Numeral Systems Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation www.telerik.com
  • 2. Table of Contents 1. Numerals Systems Binary and Decimal Numbers Hexadecimal Numbers Conversion between Numeral Systems 3. Representation of Numbers Positive and Negative Integer Numbers Floating-Point Numbers 4. Text Representation 2
  • 4. Decimal numbers (base 10) Represented using 10 numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Each position represents a power of 10: 401 = 4*102 + 0*101 + 1*100 = 400 + 1 130 = 1*102 + 3*101 + 0*100 = 100 + 30 9786 = 9*103 + 7*102 + 8*101 + 6*100 = = 9*1000 + 7*100 + 8*10 + 6*1 Decimal Numbers 4
  • 5. Binary Numeral System 5 1 0 1 1 0 0 1 01 0 0 1 0 0 1 01 0 0 1 0 0 1 11 1 1 1 1 1 1 1 Binary numbers are represented by sequence of bits (smallest unit of information – 0 or 1)  Bits are easy to represent in electronics
  • 6. Binary numbers (base 2) Represented by 2 numerals: 0 and 1 Each position represents a power of 2:  101b = 1*22 + 0*21 + 1*20 = 100b + 1b = 4 + 1 = = 5  110b = 1*22 + 1*21 + 0*20 = 100b + 10b = 4 + 2 = = 6  110101b = 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20 = = 32 + 16 + 4 + 1 = = 53 Binary Numbers 6
  • 7. Binary to Decimal Conversion Multiply each numeral by its exponent:  1001b = 1*23 + 1*20 = 1*8 + 1*1 = = 9  0111b = 0*23 + 1*22 + 1*21 + 1*20 = = 100b + 10b + 1b = 4 + 2 + 1 = = 7  110110b = 1*25 + 1*24 + 0*23 + 1*22 + 1*21 = = 100000b + 10000b + 100b + 10b = = 32 + 16 + 4 + 2 = = 54 7
  • 8. Decimal to Binary Conversion Divide by 2 and append the reminders in reversed order: 500/2 = 250 (0) 250/2 = 125 (0) 125/2 = 62 (1) 62/2 = 31 (0) 500d = 111110100b 31/2 = 15 (1) 15/2 = 7 (1) 7/2 = 3 (1) 3/2 = 1 (1) 1/2 = 0 (1) 8
  • 9. Hexadecimal Numbers Hexadecimal numbers (base 16)  Represented using 16 numerals: 0, 1, 2, ... 9, A, B, C, D, E and F Usually prefixed with 0x 0  0x0 8  0x8 1  0x1 9  0x9 2  0x2 10  0xA 3  0x3 11  0xB 4  0x4 12  0xC 5  0x5 13  0xD 6  0x6 14  0xE 7  0x7 15  0xF 9
  • 10. Hexadecimal Numbers (2) Each position represents a power of 16:  9786hex = 9*163 + 7*162 + 8*161 + 6*160 = = 9*4096 + 7*256 + 8*16 + 6*1 = = 38790  0xABCDEFhex = 10*165 + 11*164 + 12*163 + 13*162 + 14*161 + 15*160 = = 11259375 10
  • 11. Hexadecimal to Decimal Conversion Multiply each digit by its exponent  1F4hex = 1*162 + 15*161 + 4*160 = = 1*256 + 15*16 + 4*1 = = 500d  FFhex = 15*161 + 15*160 = = 240 + 15 = = 255d 11
  • 12. Decimal to Hexadecimal Conversion Divide by 16 and append the reminders in reversed order 500/16 = 31 (4) 31/16 = 1 (F) 500d = 1F4hex 1/16 = 0 (1) 12
  • 13. Binary to Hexadecimal (and Back) Conversion The conversion from binary to hexadecimal (and back) is straightforward: each hex digit corresponds to a sequence of 4 binary digits: 0x0 = 0000 0x8 = 1000 0x1 = 0001 0x9 = 1001 0x2 = 0010 0xA = 1010 0x3 = 0011 0xB = 1011 0x4 = 0100 0xC = 1100 0x5 = 0101 0xD = 1101 0x6 = 0110 0xE = 1110 0x7 = 0111 0xF = 1111 13
  • 14. Numbers Representation Positive and Negative Integers and Floating-Point Numbers
  • 15. Representation of Integers A short is represented by 16 bits 100 = 26 + 25 + 22 = = 00000000 01100100 An int is represented by 32 bits 65545 = 216 + 23 + 20 = = 00000000 00000001 00000000 00001001 A char is represented by 16 bits ‘0’ = 48 = 25 + 24 = = 00000000 00110000 15
  • 16. Positive and Negative Numbers A number's sign is determined by the Most Significant Bit (MSB) Only in signed integers: sbyte, short, int, long Leading 0 means positive number  Leading 1 means negative number Example: (8 bit numbers) 0XXXXXXXb > 0 e.g. 00010010b = 18 00000000b = 0 1XXXXXXXb < 0 e.g. 10010010b = -110 16
  • 17. Positive and Negative Numbers (2) The largest positive 8-bit sbyte number is: 127 (27 - 1) = 01111111b The smallest negative 8-bit number is: -128 (-27) = 10000000b The largest positive 32-bit int number is: 2 147 483 647 (231 - 1) = 01111…11111b The smallest negative 32-bit number is: -2 147 483 648 (-231) = 10000…00000b 17
  • 18. Representation of 8-bit Numbers +127 = 01111111 ... +3 = 00000011 +2 = 00000010 +1 = 00000001 +0 = 00000000 -1 = 11111111 -2 = 11111110 -3 = 11111101 ... -127 = 10000001 -128 = 10000000 Positive 8-bit numbers have the format 0XXXXXXX Their value is the decimal of their last 7 bits (XXXXXXX) Negative 8-bit numbers have the format 1YYYYYYY Their value is 128 (27) minus (-) the decimal of YYYYYYY 10010010b = 27 – 10010b = = 128 - 18 = -110 18
  • 19. Floating-Point Numbers Floating-point numbers representation (according to the IEEE 754 standard*): Example: 19 2k-1 20 2-1 2-2 2-n S P0 ... Pk-1 M0 M1 ... Mn-1 Sign Exponent Mantissa 1 10000011 01010010100000000000000 Mantissa = 1,322265625Exponent = 4Sign = -1 Bits [22…0]Bits [30…23]Bit 31 * See http://en.wikipedia.org/wiki/Floating_point
  • 21. How Computers Represent Text Data? A text encoding is a system that uses binary numbers (1 and 0) to represent characters  Letters, numerals, etc. In the ASCII encoding each character consists of 8 bits (one byte) of data ASCII is used in nearly all personal computers In the Unicode encoding each character consists of 16 bits (two bytes) of data Can represent many alphabets 21
  • 22. Character Codes – ASCIITable Excerpt from the ASCII table Binary Code Decimal Code Character 01000001 65 A 01000010 66 B 01000011 67 C 01000100 68 D 00100011 35 # 01100000 48 0 00110001 49 1 01111110 126 ~ 22
  • 23. Strings of Characters Strings are sequences of characters Null-terminated (like in C) Represented by array Characters in the strings can be: 8 bit (ASCII / windows-1251 / …) 16 bit (UTF-16) … … … … … … … … 0 4 bytes length … … … … … … 23
  • 25. Exercises 1. Write a program to convert decimal numbers to their binary representation. 2. Write a program to convert binary numbers to their decimal representation. 3. Write a program to convert decimal numbers to their hexadecimal representation. 4. Write a program to convert hexadecimal numbers to their decimal representation. 5. Write a program to convert hexadecimal numbers to binary numbers (directly). 6. Write a program to convert binary numbers to hexadecimal numbers (directly). 25
  • 26. Exercises (2) 7. Write a program to convert from any numeral system of given base s to any other numeral system of base d (2 ≤ s, d ≤ 16). 8. Write a program that shows the binary representation of given 16-bit signed integer number (the C# type short). 9. * Write a program that shows the internal binary representation of given 32-bit signed floating-point number in IEEE 754 format (the C# type float). Example: -27,25  sign = 1, exponent = 10000011, mantissa = 10110100000000000000000. 26

Editor's Notes

  1. 2##
  2. 3##
  3. 4##
  4. 6##
  5. 7##
  6. 8##
  7. 9##
  8. 10##
  9. 11##
  10. 12##
  11. 14##
  12. 15##
  13. 16##
  14. 17##
  15. 18##
  16. 20##
  17. 21##
  18. 22##
  19. 25##