Navi
Showing posts with label Chapter 2 ( Data Representation ). Show all posts

Number base convertion ( Tutorial )


Decimal To binary
Question 1: Convert 112 from decimal to binary.

112 = 64 + 32 + 16 = 1×26 + 1×25 + 1×24 + 0×23 + 0×22 + 0×21 + 0×20 = 11100002

Question 2: Convert 25673 from decimal to binary.


25673 = 16384 + 8192 + 1024 + 64 + 8 + 1 = 1×214 + 1×213 + 0×212 + 0×211 + 1×210 + 0×29 + 0×28 + 0×27 + 1×26 + 0×25 + 0×24 + 1×23 + 0×22 + 0×21 + 1×20 = 1100100010010012

Question 3: Convert 555 from decimal to binary.

555 = 512 + 32 + 8 + 2 + 1 = 1×29 + 0×28 + 0×27 + 0×26 + 1×25 + 0×24 + 1×23 + 0×22 + 1×21 + 1×20 = 10001010112

Question 4: Convert 100 from decimal to binary.

100 = 64 + 32 + 4 = 1×26 + 1×25 + 0×24 + 0×23 + 1×22 + 0×21 + 0×20 = 11001002

Question 5: Convert 12999 from decimal to binary.

12999 = 8192 + 1024 + 64 + 8 + 1 = 1×213 + 1×212 + 0×211 + 0×210 + 1×29 + 0×28 + 1×27 + 1×26 + 0×25 + 0×24 + 0×23 + 1×22 + 1×21 + 1×20 = 110010110001112


Decimal To Octal 

Question 1: Convert 128 to octal form.

Solution:
Given decimal number is 128
Start the division process
8 | 128
8 | 16 -- 0
8 | 2 -- 0
8 | 0 --2

Correct answer is The equivalent octal number for 128 is 2008

Question 2: Convert 58 to octal form
Solution:
Given decimal number is 58
Start the division process
8 | 58
8 | 7 -- 2
8 | 0 --7

Correct answer is the equivalent octal number for 58 is 728

Question 3: Convert 451 to octal form

Solution:
Given decimal number is 451
Start the division process
8 | 451
8 | 56 -- 3
8 | 7 -- 0
8 | 0 -- 7

Correct answer is the equivalent octal number for 128 is 7038

Question 4: Convert 4 to octal form?

Solution:
Given decimal number is 4
Since 4 is less than 7

Correct answer is the equivalent octal number for 4 is 48

Question 5: Convert 287 to octal form.

Solution:
Given decimal number is 287
Start the division process
8 | 287
8 | 35 -- 7
8 | 4 -- 3
8 | 0 --4

Correct answer is the equivalent octal number for 287 is 4378


Decimal To Hexadecimal

Question 1: Convert 56 from decimal to hexadecimal.

5610 = 1×25 + 1×24 + 1×23 + 0×22 + 0×21 + 0×20 = 1110002 = 0011 10002 = 38H

Question 2: Convert 273 from decimal to hexadecimal.

27310 = 1×28 + 0×27 + 0×26 + 0×25 + 1×24 + 0×23 + 0×22 + 0×21 + 1×20 = 1000100012 = 0001 0001 00012 = 111H

Question 3: Convert 105 from decimal to hexadecimal.

10510 = 1×26 + 1×25 + 0×24 + 1×23 + 0×22 + 0×21 + 1×20 = 11010012 = 0110 10012 = 69H

Question 4: Convert 158 from decimal to hexadecimal.

15810 = 1×27 + 0×26 + 0×25 + 1×24 + 1×23 + 1×22 + 1×21 + 0×20 = 100111102 = 1001 11102 = 9EH

Question 5: Convert 171 from decimal to hexadecimal.

17110 = 1×27 + 0×26 + 1×25 + 0×24 + 1×23 + 0×22 + 1×21 + 1×20 = 101010112 = 1010 10112 = ABH



Binary To  Decimal

Convert the following binary numbers to decimal:
a) 101110
b) 1110101

Solution:
Binary numbers: base (radix) = 2
a) 1*25 + 0*2 + 1*23 + 1*2 + 1*2 + 0*20 = 32 + 0 + 8 + 4 + 2 + 0 = 46
b) 1*26+1*25+1*24+0*23+1*22+0*21+1*2= 64 + 32 + 16 + 0 + 4 + 0 + 1 = 117




Convert the binary numbers into decimal numbers
1. 11
2. 101
3. 1111
4. 110111011
5. 1111100011110011

Solution:
1. 11 = 1*21 + 1*20 = 2 + 1 = 3
2. 101 = 1*22 + 0*21 + 1*20 = 4 + 1 = 5
3. 1111 = 1*23 + 1*22 + 1*21 + 1*20 = 8 + 4 + 2 + 1 = 15
4. 110111011 = 1*28 + 1*27 + 0*26 + 1*25 + 1*24 + 1*23 + 0*22 + 1*21 + 1*20 = 256 + 128 + 32 + 16 + 8 + 2 + 1 = 443
5. 1111100011110011 = 1*215 + 1*214 + 1*213 + 1*212 + 1*211 + 0*210 + 0*29 + 0*28 + 1*27 + 1*26 + 1*25 + 1*24 + 0*23 + 0*22 + 1*21 + 1*20
= 32768 + 16384 + 8192 + 4096 + 2048 + 128 + 64 + 32 + 16 + 2 + 1 = 63731




Binary to Octal



Convert the binary number 10101012 to octal

Solution:
Given binary number is 10101012
First we convert given binary to decimal

10101012 = (1 * 26) + (0 * 25 ) + (1 * 24) + (0 * 23) + (1 * 22) + (0 * 21) + (1 * 20)
= 64 + 0 + 16 + 0 + 4 + 0 + 1
= 64 + 21
= 85  (Decimal form)

Now we will convert this decimal to octal form
8 | 85
-------
8 | 10 -- 5
-------
8 | 1 -- 2
-------
8 | 0 --1

Correct answer is equivalent octal form is 1258



Binary to Hexadecimal

Question 1: Convert 10010001 from unsigned binary to hexadecimal.

10012 = 910 and 00012 = 110.
100100012 = 9110

Question 2: Convert 101010 from unsigned binary to hexadecimal.

102 = 210 and 10102 = A10.
1010102 = 2A10

Question 3: Convert 100110101 from unsigned binary to hexadecimal.

12 = 110, 00112 = 310 and 01012 = 510.
1001101012 = 13510

Question 4: Convert 1010101001 from unsigned binary to hexadecimal.

102 = 210, 10102 = A10 and 10012 = 910.
10101010012 = 2A910

Question 5: Convert 1100111 from unsigned binary to hexadecimal.

1102 = 610 and 01112 = 710.
11001112 = 6710


Octal To Binary

Question 1: Convert 418 to a binary number.

Solution:

Given number is 418
418 = (4 * 81) + (1 * 80)
= 4 * 8 + 1 * 1
= 32+1
= 33(Decimal number)

Now convert this decimal number to a binary number.

2 | 33
2 | 16 -- 1
2 | 8  -- 0
2 | 4  --0
2 | 2  -- 0
      1 -- 0

The binary number is 1000012

Question 2: Convert 278 to a binary number.

Solution:

Given number is 278
278 = (2 * 81) + (7 * 80)
= 2 * 8 + 7 * 1
= 16 + 7
= 23(Decimal number)

Now convert this decimal number to a binary number.

2 | 23
2 | 11 -- 1
2 | 5   -- 1
2 | 2   --1
2 | 1   -- 0
2 | 0   -- 1

The binary number is 101112

Question 3: Convert 108 to a binary number.
Solution:

Given number is 108
108 = (1 * 81) + (0 * 80)
= 1 * 8 + 0 * 1
= 8 + 0
= 8(Decimal number)

Now convert this decimal number to a binary number.

2 | 8 -- 0
2 | 4 --0
2 | 2 -- 0
     1

The binary number is 10002



Octal To Decimal


Question 1: Convert 57468 to decimal number

Solution:
The given number is 57468

57468 = (5 * 8^3)+ (7 * 8^2) + (4 * 8^1) + (6 * 8^0)
=5 * 512 + 7 * 64 + 4 * 8 + 6 * 1
= 2560+448+32+6
= 3046

The equivalent decimal number for 57468 is 3046

Question 2: Convert 2018 to decimal number

Solution:
The given number is 2018

2018 = (2 * 8^2) + (0 * 8^1) + (1 * 8^0)
= 2 * 64 + 0 * 8 + 1 * 1
= 128+0+1
= 129

The equivalent decimal number for 2018 is 129


Question 3: Convert 548 to decimal number

Solution:

The given number is 548
548 = (5 * 8^1) + (4 * 8^0)
=5 * 8 + 4 * 1
= 40 + 4
= 44

The equivalent decimal number for 548 is 44



Question 4: Convert 108 to decimal number

Solution:
The given number is 108

108 = (1 * 8^1) + (0 * 8^0)
= 1 * 8 + 0 * 1
= 8+0
= 8

The equivalent decimal number for 108 is 8



Octal To Hexadecimal

Question 1: Convert 10028 to hexadecimal

Solution:
The given number is 10028

10028 = (1 * 83)+ (0 * 82) + (0 * 81) + (2 * 80)
=1 * 512 + 0 * 64 + 0 * 8 + 2 * 1
= 512 + 0 + 0+ 2
= 514(decimal number)

Now we convert the above decimal to hexadecimal

16 | 514
16 | 32   --2
        2 -- 0

The hexadecimal number is 202

Question 2: Convert 1008 to hexadecimal

Solution:
The given number is 1008

10028 = (1 * 82) + (0 * 81) + (0 * 80)
= 1 * 64 + 0 * 8 + 0 * 1
= 64 + 0 + 0
= 64(decimal number)

Now we convert the above decimal to hexadecimal

16 | 64
16 | 4   --0
16 | 0   -- 4

The hexadecimal number is 40

Question 3: Convert 158 to hexadecimal

Solution:
The given number is 158

158 =(1 * 81) + (5 * 80)
= 1 * 8 + 5 * 1
= 8 + 5
= 13(decimal number)

Now we convert the above decimal to hexadecimal
13 is less than 16 so the equivalent hexadecimal number is D
The hexadecimal number is D

158 = D16


Hexadecimal To Decimal

Question 1: Convert 35 from hexadecimal to decimal.

3×16 + 5 = 53.

Question 2: Convert 1AA from hexadecimal to decimal.

1×16^2 + 10×16 + 10 = 426.

Question 3: Convert 12 from hexadecimal to decimal.

1×16 + 2 = 18.

Question 4: Convert 4B from hexadecimal to decimal.

4×16 + B = 75.

Question 5: Convert 89 from hexadecimal to decimal.

8×16 + 9 = 137.


Hexadecimal To Octal



Example: Convert the Hexadecimal (B 5 A)16 to its octal equivalent
Hex to Octal Conversion

The equivalent octal number is (5 5 3 2)8



Octal To Hexadecimal

Example: Convert octal number (7 5 2)8 to its equivalent hex number
Octal to Hex Conversion

The hex number equivalent is (1 D 9)8



Conversion Table
Decimal
Binary
Octal
Hexadecimal
0
0000
0
0
1
0001
1
1
2
0010
2
2
3
0011
3
3
4
0100
4
4
5
0101
5
5
6
0110
6
6
7
0111
7
7
8
1000
10
8
9
1001
11
9
10
1010
12
A
11
1011
13
B
12
1100
14
C
13
1101
15
D
14
1110
16
E
15
1111
17
F















































Number Bases

  • Binary [Base 2]
  • Octal [Base 8]
  • Decimal [Base 10]
  • Hexadecimal [Base 16]

The Decimal Number System
The Base 10 number system uses the digits : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

The Decimal Number System (denary representation) uses base 10. It includes the digits from 0 through 9. The weighted values for each position is as follows:




Therefore Radix = 10
Decimal value of the number depending on the position of each digit in the sequence:
Sequence: dn-1, .... d2, d1, d0
Value: dn-1-rn-1 + .... d2.r2 + + d0.r0 d1.r1
Examples of Decimal Numbers:
4785 = 4 x 103 + 7 x 102 + 8 x 101 + 5 x 100
         = 4 x 1000 + 7 x 100 + 8 x 10 + 5 x 1 
         = 4000 + 700 + 80 + 5.

Decimal number
Reduce power by 1 each time moving to the right point radix. Examples of Decimal Numbers
0543 = 0 x 100 + 5 x 10-1 + 4 x 10-2 + 3 x 10-3
          = 0 x 1/1 + 5 x 1/10 + 4 x 1/100 + 3 x 1/1000 = 0 + 5 x 0.1 + 4 x 0:01 + 3 x 0,001 
          = 0 + 0.5 +0.04 + 0,003.


The Binary Number System

1. In the computer, the data is encoded in electrical signals. Binary coding is commonly used for:
2. Computer or electronic device circuit can mewakilikan two conditions state (bistable device).
3. Binary coding in accordance with Boolean algebra.


Problem with Binaries number
1. Difficult to read or easy to make mistakes.
2. Binaries elusive man.
3. Example: When henyak state memory address.

  • To specify the address of a variable. If there is a 64KB memory area.
  • Therefore, there are 64 x 1024 memory cell (location)
  • 65,536 locations with addresses from 0 to 65.535.
  • If the binary, from = 0 to 00000000 00000000 11111111 11111111 = 65,535.

4.    This makes it difficult for programmers who want to specify the address of a variable.

Solution:

1. Use decimal numbers.
2. Use a bit more space.
3. Readable.
4. Programming but sometimes want to know certain bits in a 'bit location'.
5. example:

  • Do MSD for 289 510 is on OR off?.
  • What is 4 Left-Most bit to 289 510
  • To know, we have to change the whole number of decimal to binary. Difficult!


6.   Use the number system "to describe a group of digits bits".

  • Example: 3-bit or 4-bit.



       Although 910 = 10012, the number 9 is not necessarily represented by 1001 only the    
       computer, this might be represented by a number (still a combination of 0 & 1) are    
       longer. To get: -


  • Pleasure manipulate numbers. If the numbers are marked, all arithmetic operations can be produced by mixing only.
  • Density and efficiency. A little bit more, more compact, shorter circuit, faster.
  • Accuracy. many bits, to be exact.
  • Compromise with density. Therefore, the need to use different formats for different data types.
  • Data communication standard. data should be compatible with various devices that carry it.



The Octal Number System

1. Alphabet consisting of octal numbers 0, 1, 2, 3, 4, 5, 6, 7
2. Therefore, Radix = 8
3. Each octal digits can be represented by 3 bits
4. Converting a binary number to octal
5. Collect in compilation 3 bits (beginning with radix point)
6. Example: 11001001110111102

001
100
100
111
011
110
1
4
4
7
3
6

by the 11001001110111102 = 1447368 Is the MSB of 21 578? 28 = 25 178 0102 by the MSB is 0 What is 4 Left-Most bit of 25 178? 18 = 0012 and 78 = 1112 So, the Left-Most Bit 4 is 25 178 1111.


 The Hexadecimal number system

Ø  Alphabet consisting of hexadecimal numbers 0, 1, 2, 3, 4, 5, 6, 7.8, 9, A, B, C, D, E, F
Ø  Therefore, Radix = 16
Ø  Each digit HEX can be represented by 4 bits
Ø  Converting binary to Hex.
Ø  Collect in assembly 4 bits (start from point radix)
Ø  Example: 11001001110111102


1100
1001
1101
1110
C
9
D
E

Ø  Therefore, 11001001110111102 = C9DE16
Ø  Hex numbers in accordance with memory storage unit.
Ø  A cell = 1 byte = 2 groups of 4 bits (nibble) = 2 digit Hex
Ø  Therefore, the address for the memory size of 256 bytes can be represented from     00 to FF.



Introduction to Data Representation


Arithmetic Logic Unit
  • everything else in the computer is there to serviice this unit
  • Handles Integers.
  • Does the calculations.
  • may handle floaing point numbers.

 Data Types 
  • epresented in binary-coded form
  • only have 0&1 to represent everything
  • can be classified to these categories:        

  1. Numbers used in arithmetic computation
  2. Letters of the alphabet used in data processing
  3. Other discrete symbols used for specific purpose                    

Alphanumeric Representation
An alphanumeric character set is a set of elements that includes the 10 decimal digits, the 26 letters of the alphabet and a number of special character such as $, +, and =.

1. The standard alphanumeric binary code : ASCII (American Standard Code for Information          Interchange)
  • uses seven bits to code 128 characters.
  • codes must be in binary because registers can only hold binary information.



2. Another alphanumeric code used in IBM equipment, EBCDIC (Extended BCD Interchange Code) that used 8 bits for each character.
  • BCD (Binary Coded Decimal) represents each individual digit of a decimal number as a group of binary bits; the other formats would convert an entire decimal value to its equivalent binary value. *In the 8421 Binary Coded Decimal (BCD) representation each decimal digit is converted to its 4-bit pure binary equivalent.