C programming - Conversion problems


Conversion Problems :-

1.      Convert each of the following binary numbers to octal, decimal, and hexadecimal formats.
®    (111011101)2
to octal: 111 011 101 = (735)8
to decimal: =(1x28) + (1x27) + (1x26) + (1x24) + (1x23) + (1x22)  + (1x20)
                        = 256 + 128 + 64 + 16 + 8 + 4 + 1
= (477)10
to hexadecimal: 0001 1101 1101 = (1DD)16

®    (10101010111)2
to octal: 010   101   010   111 = (2527)8
to decimal: =(1x210) + (1x28) + (1x26) + (1x24) + (1x22)
 + (1x21) + (1x20)
= 1024 + 256 + 64 + 16 + 4 + 2 + 1
= (1367)10
to hexadecimal: = 0101   0101   0111 =  (557)16
®    (111100000)2
to octal: = 111   100   000  = (740)8
to decimal: =(1x28) + (1x27) + (1x26) + (1x25)
= 256 + 128 + 64 + 32
= (480)10
to hexadecimal: = 0001   1110     0000  = (1E0)16

2.      Convert each of the following octal numbers to binary, decimal, and hexadecimal formats.
®    (3754)8
to binary:   = (11 111 101 100)2
to decimal:            =(3x83) + (7x82) + (5x81) + (4x80)
= 1536 + 448 + 40 + 4
= (2028)10
to hexadecimal:     = (0111 1110 1100)2
= (7EC)16

®    (7777)8
to binary: = (111 111 111 111)2
to decimal =(7x83) + (7x82) + (7x81) + (7x80)
= 3584 + 448 + 56 + 7
= (4095)10
to hexadecimal: = (1111 1111 1111)2
= (FFF)16
®    (247)8
to binary: = (10 100 111)2
to decimal: =(2x82) + (4x81) + (7x80)
= 128 + 32 + 7
= (167)10
to hexadecimal: = (1010 0111)2
= (A7)16

3.      Convert each of the following decimal numbers to binary, octal, and hexadecimal formats.
®    (3479)10
to binary: = 3479 ÷2 = 1739
rem = 1
1739 ÷2 = 869
rem = 1
869 ÷2 = 434
rem = 1
434 ÷2 = 217
rem = 0
217 ÷2 = 108
rem = 1
108 ÷2 = 54
rem = 0
54 ÷2 = 27
rem = 0
27 ÷2 = 13
rem = 1
13 ÷2 = 6
rem = 1
6 ÷2 = 3
rem = 0
3 ÷2 = 1
rem = 1
1 ÷2 = 0
rem = 1
reading bottom to top of remainders = (110110010111)2

to octal: = 3479 ÷8 = 434
rem = 7
434 ÷8 = 54
rem = 2
54 ÷8 = 6
rem = 6
6 ÷8 = 0
rem = 6
reading bottom to top of remainders = (6627)8

to hexadecimal: = 3479 ÷16 = 217
rem = 7
217 ÷16 = 13
rem = 9
13 ÷16 = 0
rem = 13 (D)
reading bottom to top of remainders = (D97)16

®    (642)10
to binary: = 642 ÷2 = 321
rem =0
321 ÷2 = 160
rem = 1
160 ÷2 = 80
rem = 0
80 ÷2 = 40
rem = 0
40 ÷2 = 20
rem = 0
20 ÷2 = 10
rem = 0
10 ÷2 = 5
rem = 0
5 ÷2 = 2
rem = 1
2 ÷2 = 1
rem = 0
1 ÷2 = 0
rem = 1
reading bottom to top of remainders = (1010000010)2

to octal: = 642 ÷8 = 80
rem = 2
80 ÷8 = 10
rem = 0
10 ÷8 = 1
rem = 2
1 ÷8 = 0
rem = 1
reading bottom to top of remainders = (1202)8

to hexadecimal: = 642 ÷16 = 40
rem = 2
40÷16 = 2
rem = 8
2 ÷16 = 0
rem = 2
reading bottom to top of remainders = (282)16

®    (555)10
to binary: = 555 ÷2 = 277
rem = 1
277 ÷2 = 138
rem = 1
138 ÷2 = 69
rem = 0
69 ÷2 = 34
rem = 1
34 ÷2 = 17
rem = 0
17 ÷2 = 8
rem = 1
8 ÷2 = 4
rem = 0
4 ÷2 = 2
rem = 0
2 ÷2 = 1
rem = 0
1 ÷2 = 0
rem = 1
reading bottom to top of remainders = (1000101011)2

to octal: = 555 ÷8 = 69
rem = 3
69 ÷8 = 8
rem = 5
8 ÷8 = 1
rem = 0
1 ÷8 = 0
rem =1
reading bottom to top of remainders = (1053)8

to hexadecimal: = 555 ÷16 = 34
rem = 11 (B)
34 ÷16 = 2
rem = 2
2 ÷16 = 0
rem = 2
reading bottom to top of remainders = (22B)16


4.      Convert each of the following hexadecimal numbers to binary, octal, and decimal formats.
®    (4FB2)16
to binary: (100 1111 1011 0010)2
to octal: (100 1111 1011 0010)2
= (47662)8
to decimal: = (4x163) + (15x162) + (11x161) + (2x160)
= (4x4096) + (15x256) + (11x16) + (2x1)
= 16384 + 3840 + 176 + 2
= (20402)10
®    (88BAE)16
to binary: (1000 1000 1011 1010 1110)2
to octal: (10 001 000 101 110 101 110)2
= (2105656)8
to decimal: = (8x164) + (8x163) + (11x162) + (10x161) + (14x160)
= (8x65536) + (8x4096) + (11x256) + (10x16) + (14x1)
= 16384 + 3840 +176 + 14
= (560046)10
®    (DC4)16
to binary: (1101 1100 0100)2
to octal: (110 111 000 100)2
= (6704)8
to decimal: = (13x162) + (12x161) + (4x160)
= (13x256) + (12x16) + (4x1)
= 3328 + 192 + 4
= (3524)10

Fractional numbers:


5.      Conversion from binary number system to decimal system
111.112            = 1 x 22 + 1 x 21+ 1 x 20 + 1 x 2-1 + 1 x 2-2
                        =    4     +    2     +    1     +    1/2   +   ¼   =  7.7510


Conversion from decimal number system to binary system
7.7510= (?)2
6.      Conversion of the integer part
710=( 111)2
Conversion of the fractional part:
perform a repeated multiplication by 2 and extract the integer part of the result
            0.75 x 2 =1.50 Þextract 1
            0.5 x 2 = 1.0    Þ extract 1                                                    0.7510 = 0.112
            0.0              Þ stop
             \  Combine the results from integer and fractional part, 7.7510 = 111.112


7.      Convert (0.625)10  to its binary form
Solution:          0.625 x 2 = 1.25          Þ extract 1
                        0.25 x 2 = 0.5 Þ extract 0
                        0.5 x 2 = 1.0    Þ extract 1
                        0.0       Þ stop
\ (0.625)10 = (0.101)2




8.      Convert (0.6)10  to its binary form

0.6 x 2 = 1.2    Þ extract 1
0.2 x 2 = 0.4    Þ extract 0
0.4 x 2 = 0.8    Þ extract 0
0.8 x 2 = 1.6    Þ extract 1
0.6 x 2 =          Þ        ( same as 1st one )       
\ (0.6)10 = (0.1001 1001 1001 …)2


9.      Convert (0.8125)10  to its binary form
0.8125 x 2 = 1.625      Þ extract 1
 0.625 x 2 = 1.25         Þ extract 1
0.25 x 2 = 0.5 Þ extract 0
0.5 x 2 = 1.0    Þ extract 1
0.0       Þ stop
\ (0.8125)10 = (0.1101)2


 Credits-- Madhan

0 comments: