Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation www.telerik.com.

Slides:



Advertisements
Similar presentations
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
Advertisements

How Computers Represent Numbers Friday, Week 5. Binary Code A series of 1’s and 0’s Place value is in powers of 2.
Representing Information as Bit Patterns
04/03/10CPE1002 (c) Monash University1 Number Systems and Data Representation Monash University School of Network Computing CPE 1002.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.

Introduction to Programming with Java, for Beginners
Floating Point Numbers
Data Representation in Computers
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Binary Number Systems.
Binary Representation and Computer Arithmetic
Chapter 5 Data representation.
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Computers Organization & Assembly Language
CS-280 Dr. Mark L. Hornick 1 ASCII table. 2 Displaying Numbers as Text Problem: display numerical values as text Consider the numerical value 0x5A held.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
COMPSCI 210 Semester Tutorial 1
Number Systems Spring Semester 2013Programming and Data Structure1.
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
The Teacher CP4 Binary and all that… CP4 Revision.
CISC105 – General Computer Science Class 9 – 07/03/2006.
The Teacher CP4 Binary and all that… CP4 Revision.
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Data Representation, Number Systems and Base Conversions
AEEE2031 Data Representation and Numbering Systems.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Very Basic Mathematical Concepts for Programmers
DECIMALBINARY a) b) c) d) e) f) Revision Exercise DECIMALBINARY a) b) c)
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Number Systems Denary Base 10 Binary Base 2 Hexadecimal Base 16
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Number Representation Lecture Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Objects Variables and Constants. Our Scuba Problem #include // cin, cout, > using namespace std; int main() { const double FEET_PER_ATM = 33.0, LBS_PER_SQ_IN_PER_ATM.
Number Systems and Computer Arithmetic Winter 2014 COMP 1380 Discrete Structures I Computing Science Thompson Rivers University.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
1 Bits, Bytes, Binary & Hex CIS TAG ▪ Byte Bit.
Base 16 (hexadecimal) Uses the decimal digits and the first letters of the alphabet to encode 4 binary bits (16=2 4 ) abcdef or ABCDEF.
Binary, Decimal and Hexadecimal Numbers Telerik Software Academy C# Fundamentals – Part 2.
Programming and Data Structure
Lec 3: Data Representation
Data Representation.
Number Representation
Data Representation Binary Numbers Binary Addition
CSCI 198: Lecture 4: Data Representation
CSCI 161: Lecture 4: Data Representation
EPSII 59:006 Spring 2004.
Binary, Decimal and Hexadecimal Numbers
CS1010 Programming Methodology
Cosc 2P12 Week 2.
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Cosc 2P12 Week 2.
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Presentation transcript:

Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation

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

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* * *10 0 =  130= 1* * *10 0 =  9786= 9* * * *10 0 = = 9* * *10 + 6*1 4

 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 :  101 b = 1* * *2 0 = 100 b + 1 b = = = 5  110 b = 1* * *2 0 = 100 b + 10 b = = = 6  b = 1* * * * * *2 0 = = = = 53 6

 Multiply each numeral by its exponent:  1001 b = 1* *2 0 = 1*8+ 1*1= = 9 = 9  0111 b = 0* * * *2 0 = = 100 b + 10 b + 1 b = = = 7  b = 1* * * * *2 1 = = b b b + 10 b = = = = 54 7

 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) 500 d = b 62/2 = 31 (0) 500 d = b 31/2 = 15 (1) 31/2 = 15 (1) 15/2 = 7 (1) 15/2 = 7 (1) 7/2 = 3 (1) 7/2 = 3 (1) 3/2 = 1 (1) 3/2 = 1 (1) 1/2 = 0 (1) 1/2 = 0 (1) 8

 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  0x210  0xA 3  0x311  0xB 4  0x412  0xC 5  0x513  0xD 6  0x614  0xE 7  0x715  0xF 9

 Each position represents a power of 16 :  9786 hex = 9* * * *16 0 = = 9* *256+ 8*16+ 6*1= =  0xABCDEF hex = 10* * * * * *16 0 = 13* * *16 0 = =

 Multiply each digit by its exponent  1F4 hex = 1* * *16 0 = = 1* *16+ 4*1 = = 500 d  FF hex = 15* *16 0 = = = = 255 d 11

 Divide by 16 and append the reminders in reversed order 500/16 = 31 (4) 31/16 = 1 (F) 500 d = 1F4 hex 1/16 = 0 (1) 12

 The conversion from binary to hexadecimal (and back) is straightforward: each hex digit corresponds to a sequence of 4 binary digits: 0x0 = 00000x8 = x1 = 00010x9 = x2 = 00100xA = x3 = 00110xB = x4 = 01000xC = x5 = 01010xD = x6 = 01100xE = x7 = 01110xF =

Positive and Negative Integers and Floating-Point Numbers

 A short is represented by 16 bits  100= = =  An int is represented by 32 bits  = = =  A char is represented by 16 bits  ‘0’= 48 = = =

 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) 0XXXXXXX b > 0 e.g b = b = 0 1XXXXXXX b < 0 e.g b =

 The largest positive 8-bit sbyte number is: 127 ( ) = b  The smallest negative 8-bit number is: -128 ( -2 7 ) = b  The largest positive 32 -bit int number is: ( ) = 01111…11111 b  The smallest negative 32 -bit number is: ( ) = 10000…00000 b 17

+127= = = = = = = = = =  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 ( 2 7 ) minus ( - ) the decimal of YYYYYYY  b = 2 7 – b = = =

 Floating-point numbers representation (according to the IEEE 754 standard*):  Example: 19 2 k n SP 0...P k-1 M 0 M 1 M n-1 SignExponentMantissa Mantissa =1, Exponent= 4Sign=-1 Bits [22…0]Bits [30…23] Bit31 * See

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 – ASCII Table Excerpt from the ASCII table Binary Code Decimal Code Character A B C D # ~ 22

 Strings are sequences of characters  Null-terminated (like in C)  Represented by array  Characters in the strings can be:  8 bit (ASCII / windows / …)  16 bit (UTF- 16 ) ……………………\0 4 bytes length……………… 23

Questions?

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

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 = , mantissa =