Professional Documents
Culture Documents
Step
1 Evaluatethenumbertobeconverted:
Ifthedecimalnumberislessthan256,thenusethatdecimalnumberforthe4thoctet,and
padtherestwithzerossothattheresultisindotteddecimalform,withfouroctets.
Ifthenumberis>=256,thencontinuetostep2.
2 Dividethedecimalnumberby256
3 Multiplythedecimalportionoftheresultfromstep2by256
4 Subtracttheresultofstep3fromtheoriginaldecimalnumbertoyieldtheBase256octet
5 Examinethedecimalportionoftheresultfromstep2
a. Ifthatdecimalportionofthenumberislessthan256,thenusethatnumberforthenext
octet.
Usezeroesforanyremainingoctets,sothatthenumberisindotteddecimalform,with4
octets.
b. Ifthatnumberislargerthan,orequalto256,thencontinuefromstep2,usingthatnumber.
Example 1
FindthelastaddressinanIPv4subnetwithanetworkaddressof16.0.0.0/17,with32,768addressesper
subnet.
First,convertthenumberofaddresses1toBase256(dotteddecimal).32,7681=32,767
Oncetheconversioniscomplete,addthatBase256dotteddecimalvaluetothe1staddresstodeterminethe
lastaddressinthesubnet.
Firstaddressinsubnet0(the1stsubnet):
16 . 0 . 0 . 0
Numberofaddresses(32,768persubnet)1:
0 . 0 . 127 . 255
Lastaddressinsubnet0:
16 . 0 . 127 . 255
Convert32,767toanIPv4address.
1. Is32,767largerthan256?Yes.Thenproceedtostep2.
2. 32,767/256=127.996
3. 127x256=32,512
4. 32,76732,512=255(thisisthe4thoctetofthedotteddecimal)
The3rdOctet
1. Since127issmallerthan256youredonedividingandthevalueforthe3rdoctetis127
Usingzeroesforanyremainingoctetsyieldsadotteddecimalvalueof:0.0.127.255
The255isfromstep3,andthe127iswhatwasleftover.
2009Prof.Chin,ConsciousVibes.com
Lastsaved:3/6/201612:33PM
Page1of4
Example 2
Convert2,215,708,686toaBase256dotteddecimalIPv4address.
Theresultis:2,215,708,686=132.17.8.14
Check
132x2563= 2,214,592,512
17x2562=
1,114,112
8x2561=
2,048
0
14x256 =
14
2,215,708,686
Example 3
Convert1,024toBase256
Sincewereleftwith4,and4islessthan256,weuse4forthe3rdoctet
Theresult:1,024decimalisequalto0.0.4.0inBase256
2009Prof.Chin,ConsciousVibes.com
Lastsaved:3/6/201612:33PM
Page2of4
2563
16,777,216
w
2562
65,536
x
2561
256
y
2560
1
z
AnIPv4addressisa32bitnumber.Itisgenerallywritteninthe"dottedquad"notation:w.x.y.z.Toconvertan
IPaddresstobase10,calculatew*16,777,216+x*65,536+y*256+z.
http://www.everything2.com/e2node/Decimal%2520IP%2520address
Example 1
InPHP,tryip2long().
HOWit'sdone.
http://www.cre8asiteforums.com/forums/index.php?showtopic=47466
256^0=1
256^1=256
256^2=65,536
256^3=16,777,216
So,194.247.44.146is...
146*256^0=146
44*256^1=11,264
247*256^2=16,187,392
194*256^3=3,254,779,904
Addthoseup,and...
146+11,264+16,187,392+3,254,779,904=3270978706
Howdoyougobackwardson3270978706toget194.247.44.146?
Beginbydividingby256^3andcountthenumberoftimesyoucandothis.Taketheremainderanddothe
samewith256^2,256^1and256^0.
EG:3270978706/256^3=194remainder:16198802.
Example 2
http://www.everything2.com/e2node/Decimal%2520IP%2520address
2009Prof.Chin,ConsciousVibes.com
Lastsaved:3/6/201612:33PM
Page3of4
InUNIX,thesearehandledwithinet_ntoa()andinet_aton().
ToconvertdecimalIPstonormaldottedquadform(forexample,tospoilspammers'joy),usethisPerlhack:
perlMSockete"printinet_ntoa(pack('N','354267876296'));"
Replacenumberaccordingly.
Reference
DecodedecimalIPaddressto
dottedquad
ConvertandlocateIPaddresses
IPv4AddressTutorial:Converting
OctetstoBinaryandDecimal
HowtoConvertanIPAddressto10
DigitsDecimalNumber
DecimalIPAddress
URLDiscombobulator
Searchfor:convertdecimaltoip
http://toastedspam.com/decodeip
http://kloth.net/services/iplocate.php
http://countryipblocks.net/binary.php
http://ezinearticles.com/?HowtoConvertanIPAddressto10
DigitsDecimalNumber&id=1716788
http://www.everything2.com/e2node/Decimal%2520IP%2520address
http://www.karenware.com/powertools/ptlookup.asp
2009Prof.Chin,ConsciousVibes.com
Lastsaved:3/6/201612:33PM
Page4of4