Web Analytics Made Easy - Statcounter


https://www.amazon.it/dp/B0CT9YL557

We support WINRAR [What is this] - [Download .exe file(s) for Windows]

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
SITEMAP
Audiobooks by Valerio Di Stefano: Single Download - Complete Download [TAR] [WIM] [ZIP] [RAR] - Alphabetical Download  [TAR] [WIM] [ZIP] [RAR] - Download Instructions

Make a donation: IBAN: IT36M0708677020000000008016 - BIC/SWIFT:  ICRAITRRU60 - VALERIO DI STEFANO or
Privacy Policy Cookie Policy Terms and Conditions
a2 --- Numerical Conversions

[next] [previous] [top] [last] [contents] [indice ridotto] [violazione licenza] [translators] [docinfo] [indice analitico] [tome] [part]


Chapter 743.   Numerical Conversions

(1)

The computer usage requires the capacity to convert numbers expressed in different number systems; to be precise, one can request to convert numbers on a different base. Before being able convert a number in a different number system, it is necessary the understand the meaning of the decimal number system i.e. the standard one (for the human beings).

A number expressed in base 10, is interpreted by summing up the value of each single digit multiplied by 10n (n rappresents the n-nth; digit starting from zero). For example, 12 345 may be expressed as 5*100 + 4*101 + 3*102 + 2*103 + 1*104. In a similar way, one can decompose a number to express it in base 10 by repeatedly dividing the number by the base and then using each time the result of the division. For example, the number 12 345 (which obviously is already expressed in base 10), can be decomposed as follows: 12 345/10=1 234 with the remiander five; 1 234/10=123 with the remainder three; 123/10=12 with the remainder three; 12/10=1 with the remainder two; 1/10=0 with the remainder one; (when the quotient becomes null, the conversion is finished). The sequence of the remainders is the number expressed in base 10: 12 345.

743.1   Octal Numbers

The octal number sysstem, i.e. the vase 8 numbering systems, uses eight digits to represent the values: from zero to seven. The conversion technique of an octal number to a decimal number is the same as that exemplified for the decimal numbers, with the difference that the numbers base is eigth. For example to interpret the octal number 123458, one should process it as follows: 5*80 + 4*81 + 3*82 + 2*83 + 1*84. The same number could therefore be represented in base 10 as 5 349. To convert the other way round the number 5 349 (now expressed in base 10), one can process it as follows: 5 349/8=668 with the remainder of five; 668/8=83 with the remainder of four; 83/8=10 with the remainder of three; 10/8=1 with the remainder of two; 1/8=0 with the remainder of one. Now we reobtain the octal number 123458.

Image 743.1. Base eight Conversion.

32485 in base 10 --> | 32485/8 = 4060 with remainder of 5
                     |  4060/8 =  507 with remainder of 4
                     |   507/8 =   63 with remainder of 3
                     |    63/8 =    7 with remainder of 7
                     |     7/8 =    0 with remainder of 7
                     |
                     `---------------------------> 77345 in base 8

Image 743.2. Computation of the value corresponding to a value expressed in base eight.

77345 in base 8 --> |    5*8^0 =     5
                    |    4*8^1 =    32
                    |    3*8^2 =   192
                    |    7*8^3 =  3584
                    |    7*8^4 = 28672
                    |
                    `-- total = 32485 in base 10

743.2   Hexadecimal Numbers

The hexadecimal number system, i.e. the system in base 16, works in a similar way as the octal one, with the difference that uses 16 digits to reppresent the values, therefore it uses the numeric digits from zero to nine plus the letters from ``A'' to ``F'' for the larger values. In practice, the letter ``A'' is used for the number 10 and the letter ``F'' is used for the number 15.

The conversion technique is the same as that previously seen with the octal number system, with the additional difficulty of the additional letters. For example to interpret the hexadecimal number 19ADF16, one can proceed as follows: 15*160 + 13*161 + 10*162 + 9*163 + 1*164. Therefore the same number could be represented in base 10 as 105 183. The other way round, to convert the number 105 183 (here expressed in base 10), one can process it as follows: 105 183/16=6 573 with the remainder of 15, or F16; 6 573/16=410 with the remainder of 13, or D16; 410/16=25 with the remiander of 10, or A16; 25/16=1 with the remainder of nine; 1/16=0 with the remainder of one. In this way one gets back the hexadecimal number 19ADF16.

Figura 743.3. Conversion in base 16.

32485 in base 10 --> | 32485/16 = 2030 with the remainder of 5 --> 5
                     |  2030/16 =  126 with the remainder of 14 --> E
                     |   126/16 =    7 with the remainder of 14 --> E
                     |     7/16 =    0 with the remainder of  7 --> 7
                     |
                     `-----------------------------------> 7EE5 in base 16

Figura 743.4. Computation of the value corresponding to a number expressed in base 16.

7EE5 in base 16 --> |        5*16^0 =     5
                    | E --> 14*16^1 =   224
                    | E --> 14*16^2 =  3584
                    |        7*16^3 = 28672
                    |
                    `------- total = 32485 in base 10

743.3   Binary Numbers

The binary number system, i.e. in base two, uses only two digits to represent values: zero and one. This is clearly a limit example of representing values, because it uses the minimum number of digits. In practice it simplifies the conversion.

Following the logig of the previous examples, we analyse briefly the conversion of the binary number 11002: 0*20 + 0*21 + 1*22 + 1*23. Therefore, the same number could be represented as 12 according to the standard system. The other way round, to convert the number 12, one can proceed as follows: 12/2=6 with the remainder of zero; 6/2=3 with the remainder of zero; 3/2=1 with the remainder of one; 1/2=0 with the remainder of one. This way one gets back the binary number 11002.

Figura 743.5. Conversion in base two.

32485 in base 10 --> | 32485/2 = 16242 with the remainder of 1
                     | 16242/2 =  8121 with the remainder of 0
                     |  8121/2 =  4060 with the remainder of 1
                     |  4060/2 =  2030 with the remainder of 0
                     |  2030/2 =  1015 with the remainder of 0
                     |  1015/2 =   507 with the remainder of 1
                     |   507/2 =   253 with the remainder of 1
                     |   253/2 =   126 with the remainder of 1
                     |   126/2 =    63 with the remainder of 0
                     |    63/2 =    31 with the remainder of 1
                     |    31/2 =    15 with the remainder of 1
                     |    15/2 =     7 with the remainder of 1
                     |     7/2 =     3 with the remainder of 1
                     |     3/2 =     1 with the remainder of 1
                     |     1/2 =     0 with the remainder of 1
                     |
                     `---------------------------> 111111011100101 in base 2

Figura 743.6. Computation of the value corresponding to a number expressed in base two.

111111011100101 in base 2 --> |    1*2^0  =     1
                              |    0*2^1  =     0
                              |    1*2^2  =     4
                              |    0*2^3  =     0
                              |    0*2^4  =     0
                              |    1*2^5  =    32
                              |    1*2^6  =    64
                              |    1*2^7  =   128
                              |    0*2^8  =     0
                              |    1*2^9  =   512
                              |    1*2^10 =  1024
                              |    1*2^11 =  2048
                              |    1*2^12 =  4096
                              |    1*2^13 =  8192
                              |    1*2^14 = 16384
                              |
                              `--- total = 32485 in base 10

It is possible to perform the conversion in a simpler way by using a small table as follows:

16384 8192 4096 2048 1024  512  256  128  64   32   16    8    4    2    1
.--------------------------------------------------------------------------.
|    |    |    |    |    |    |    |    |    |    |    |    |    |    |    |
`--------------------------------------------------------------------------'

The values listed in each box are the sequence of the powers of two: 20, 21, 22,... 2n.

If one wants to convert a binary number to a number in base 10, it is sufficient to enter the digits into the boxes, with right alignement, to multiply each digits by the value written above and then to sum up each result. For example:

16384 8192 4096 2048 1024  512  256  128  64   32   16    8    4    2    1
.--------------------------------------------------------------------------.
|    |    |    |    |    |    |    |    |    |    |    |  1 |  0 |  1 |  0 |
`--------------------------------------------------------------------------'
                                                          8 +  0 +  2 +  0 = 10

To find the binary value correponding to a number in base 10, it is sufficient to subtract the largest possible value. Let's suppose that we want convert the number 123 in binary, one can subtract the values: 64, 32, 16, 8, 2 e 1:

16384 8192 4096 2048 1024  512  256  128  64   32   16    8    4    2    1
.--------------------------------------------------------------------------.
|    |    |    |    |    |    |    |    |  1 |  1 |  1 |  1 |  0 |  1 |  1 |
`--------------------------------------------------------------------------'
                                          64 + 32 + 16 +  8 +  4 +  2 +  1 = 123

743.3.1   Conversion among octal, hexadecimal and binary

The octal and hexadecimal number systems have the property of being easily convertable to binary and the other way round. Actually, an octal digit requires exactly three binary digits to represent it, whereas an hexadecimal digit requires four binary digits to represent it. For example, the octal number 1238 can be easily converted into the binary 0010100112; moreover the hexadecimal number 3C16 can be easily converted into 001111002.

Figura 743.10. Conversion between octal and binary numbers.

123 in base eight                       001010011 in base two
|||                                     \ /\ /\ /
||`------> 011                           |  |  |
||                                       |  |  `----> 3
|`----> 010                              |  |
|                                        |  `------> 2
`--> 001                                 |
                                         `--------> 1

=    001010011 in base two                          123 in base eight

In practice, it is sufficient to convert each octal or hexadecimal digit in the corresponding binary number. Therefore, if one considers the 1238, one obtains 0012, 0102 and 0112, that can be linked as already shown. In the same way one can proceed for the 3C16, that converts into 00112 and 11002.

Figura 743.11. Conversion between hexadecimal and decimal numbers.

3C in base sixteen                      00111100 in base two
||                                      \  /\  /
||                                        |   | 
|`-----> 1100                             |   |
|                                         |   `-----> C
`--> 0011                                 |
                                          `--------> 3

=    00111100 in base two                            3C in base sixteen

It is clearly simplified also the conversion from binary to octal and from binary to hexadecimal.

Figura 743.12. Summary of the conversion from binary to octal and from binary to hexadecimal.

 111111011100101  in base two
 \ /\ /\ /\ /\ /
  7  7  3  4  5   in base eight
 / \/ \/ \/ \/ \
0111111011100101  in base two
 \  /\  /\  /\  /
  7  14  14   5
  7   E   E   5   in base sixteen
/  \/  \/  \/  \
0111111011100101  in base two

Table 743.13. Fast conversion from binary to octal and from binary to hexadecimal.

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

Appunti di informatica libera 2006.01.01 --- Copyright © 2000-2006 Daniele Giacomini -- <daniele (ad) swlibero·org>, <daniele·giacomini (ad) poste·it>


1) Translation last update on 2003.06.19 from Mario Pesce <mario (ad) datamission·co·uk>.


It should be possible to link to this page also with the name numerical_conversions.htm

[next] [previous] [top] [last] [contents] [indice ridotto] [violazione licenza] [translators] [docinfo] [indice analitico]

Valid ISO-HTML!

CSS validator!

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2006 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Sub-domains

CDRoms - Magnatune - Librivox - Liber Liber - Encyclopaedia Britannica - Project Gutenberg - Wikipedia 2008 - Wikipedia 2007 - Wikipedia 2006 -

Other Domains

https://www.classicistranieri.it - https://www.ebooksgratis.com - https://www.gutenbergaustralia.com - https://www.englishwikipedia.com - https://www.wikipediazim.com - https://www.wikisourcezim.com - https://www.projectgutenberg.net - https://www.projectgutenberg.es - https://www.radioascolto.com - https://www.debitoformtivo.it - https://www.wikipediaforschools.org - https://www.projectgutenbergzim.com