Numerical Systems and Transformations


E-mail this post



Remember me (?)



All personal information that you provide here will be governed by the Privacy Policy of Blogger.com. More...



Our society uses numerical system based on number 10. There is a nutorious explanation why this system is used - it's simple, people have ten fingers, thus makes them easier to calculate numbers. If things were gone different, and something had messed up primordial soup -> developing Homo sapiens with eight fingers, it would be more likely we would use octal numeric system at present time. Infinite number of numerical systems exist, but following are most commonly used, and their conversion from one to another, is simple.




Decimal System:

Base: 10
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9



Octal System:

Base: 8
Digits: 0, 1, 2, 3, 4, 5, 6, 7
Example: 27 (decimal) = 33 8 (octal)



Hexadecimal (hex) System:

Base: 16
Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Example: 27 (decimal) = 1B 16 (hex)



Binary System:

Base: 2
Digits: 0, 1
Example: 27 (decimal) = 11011 2 (binary)




General Method of Transforming Numbers


Number we want to transform uses base X: we would like to transform this number into new one, that uses Y base. In this case we will use method of continuous dividing and multiplying (dividing numbers left of comma (,) with Y and multiplying numbers on the right side of comma, by Y - rational numbers). This method is best understood looking at these examples:




Example

Transform 5324 (decimal) into decimal number (?!) using method of continuous dividing – result 5324


5324 : 10 = 532 , remaining 4 100 last digit
532 : 10 = 53 , remaining
2 101
53 : 10 = 5 , remaining
3 102
5 : 10 = 0 , remaining
5 103 first digit

- end of procedure





Example

Transform 0,8125 (decimal) into decimal number (?!) using method of continuous multiplying – result 0,8125


0,8125  * 10 =   8, 125    10-1           first digit after zero
0,125 * 10 =
1, 25 10-2
0,25 * 10 = 2, 5 10-3
0,5 * 10 = 5, 0 10-4 last digit

0,0 end of procedure






Decimal 2 Binary




Example

Transform 29 (decimal) into binary number - reading upwards, result is 111012


29 : 2 =  14 , remaining 1   20            last (smallest) digit
14 : 2 = 7 , remaining
0 21
7 : 2 = 3 , remaining 1 22
3 : 2 = 1 , remaining 1 23
1 : 2 = 0 , remaining 1 24 first digit

- end of procedure





Example

Transform 0,8125 (decimal) into binary number – reading downwards, result is 0,11012


0,8125  * 2 =      1, 625    2-1            first digit after zero
0,625 * 2 =
1, 25 2-2
0,25 * 2 = 0, 5 2-3
0,5 * 2 = 1, 0 2-4 last digit

0,0 end of procedure





Example

Transform 0,3 (decimal) into binary number – result is 0,01001 1001 1001… 2 shortly rounded = 0,010012


0,3  * 2 =      0, 6         2-1       first digit after zero
0,6 * 2 =
1, 2 2-2
--------
0,2 * 2 = 0, 4 2-3
0,4 * 2 = 0, 8 2-4
0,8 * 2 = 1, 6 2-5
0,6 * 2 = 1, 2 2-6
--------



procedure never ends





Example – Quick Method

Transform 53(decimal) into binary number using quick method


  53                                                                          25 + 24 + 22 + 20 =
- 32 -> 25 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20 =

-------- 110101 2
21
- 16 -> 24
--------
5
- 4 -> 22
--------
1
- 1 -> 20
--------
0 -> end of procedure






Decimal 2 Hex




Example

Transform 2540,34 (decimal) into hex number-result ~ 9EC, 570A316


a) left from”,

2540 : 16 = 158 , remaining 12 => C        160        last digit
158 : 16 = 9 , remaining 14 =>
E 161
9 : 16 = 0 , remaining 9 =>
9 162 first digit

end of procedure => 9EC 16


b) right from “,

0,34 * 16 = 5,44 5 => 5 16-1 first digit after zero
0,44 * 16 = 7,04 7 =>
7 16-2
0,04 * 16 = 0,64 0 => 0 16-3
0,64 * 16 = 10,24 10 => A 16-4
0,24 * 16 = 3,84 3 => 3 16-5


procedure could be continued => 0, 570A3… 16



Final result ~ 9EC , 570A316






Binary 2 Decimal




Example

Transform 110101 (binary) into decimal number


110101 2 = 1*25 + 1*24 + 0*23 + 1*22 + 0*21 + 1*20
= 1*25 + 1*24 + 1*22 + 1*20

= 1*32 + 1*16 + 1*4 + 1*1

=
53 10




Example

Transform -11,101 (binary) into decimal number


-11,101 2 = - (1*21 + 1*20 + 1*2-1 + 0*2-2 + 1*2-3)
= - (1*21 + 1*20 + 1*2-1 + 1*2-3)

= - (1*2 + 1*1 + 1*0,5 + 1*0,125)

=
- 3 , 625






Hex 2 Decimal




Example

Transform 9EC,570A3 (hex) into decimal number

9EC, 570A3 16 = 9*162 + 14*161 + 12*160 + 5*16-1 + 7*16-2 + 0*16-3 + 10*16-4 + 3*16-5

= 2304 + 224 +12 + 0,3125 + 0,02734375 + 0,0001525878... + 0,00000286102...

= 2540 , 33999919891357421875






Quick Method of Transforming between Binary, Hex and Octal System


Binary Hex Binary Octal

0000 0 000 0
0001 1 001 1
0010 2 010 2
0011 3 011 3
0100 4 100 4
0101 5 101 5
0110 6 110 6
0111 7 111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F





Example

Transform -6F,A 16 into binary number


-6F,A 16  =  -  0110  1111  ,  1010  2  =  - 1101111 , 101 2




Example

Transform 11,000011001 2 into hex number

11,000011001 2   =      11  ,  0000  1100  1  2
= 0011 , 0000 1100 1000 2

= 3 , 0 C 8 16

=
3 , 0C8 16



Example

Transform 37,24 8 into binary number


37,24 8 = 011 111 , 010 100 2 = 11111 , 0101 2




Example

Transform 1111011,10011101 2 into octal number

1111011,10011101 2   =        1  111  011  ,  100  111  01  2
= 001 111 011 , 100 111 010 2

= 1 7 3 , 4 7 2 16

=
173 , 472 16






Technorati Tags:
, , , , , , , , , , ,



2 Responses to “Numerical Systems and Transformations”

  1. Anonymous Anonymous 

    Been looking for help with conversions b/w binary and decimal :) this is kool

  2. Anonymous Anonymous 

    Wow, now i suddenly understand it, very usefull :)

Leave a Reply

      Convert to boldConvert to italicConvert to link

 


German Flag Spanish Flag French Flag Italian Flag Portuguese Flag Japanese Flag Korean Flag Chinese Flag British Flag


This Website is optimized for Firefox. Users browsing with Internet Explorer may encounter problems while viewing pages.


C++ Maniac



Learn C



Additional



#include



Learn Converting



Appendix


Links


Previous posts




Daily Lessons for programming in Visual Studio, using C code.