11-10-2013 02:15 AM - edited 03-07-2019 04:30 PM
Hi All,
When we are going to specify the opsf area id, we can use two different notations:
- A decimal number in the range from 0 to 4294967295
- dotted-decimal notation similar to an IP address, such as A.B.C.D.
Now, let´s assume I want to define one area with id 259.
How can I define it in dotted-decimal notation?
Many thanks.
Solved! Go to Solution.
11-10-2013 02:36 AM
Hi Fabio,
Now, let´s assume I want to define one area with id 259.
This is about integer arithmetics in computers. Notice that a single octet can hold numbers in the range of 0-255. If you want a larger number, you need to use two octets. Here, you can have numbers of the form <0-255>.<0-255> (65536 values in total, 256x256). If you take into account that 255 can be written as 0.255, and 256 is logically 1.0, then 259=256+3=1.3.
When extending it to 4B numbers, this basic principle is retained. Assuming you have an area number N in a linear format, then its dotted decimal format A.B.C.D would be computed as follows:
A = N DIV 2^24
B = (N DIV 2^16) MOD 256
C = (N DIV 2^8) MOD 256
D = N MOD 256
For example, with N = 259:
A = 259 DIV 16777216 = 0
B = (259 DIV 65536) MOD 256 = 0 MOD 256 = 0
C = (259 DIV 256) MOD 256 = 1 MOD 256 = 1
D = 259 MOD 256 = 3
The resulting number is 0.0.1.3. To verify, the linear number should be computed back as A*2^24 + B*2^16 + C*2^8 + D = 0+0+1*256+3 = 259
With N = 942639582:
A = 942639582 DIV 16777216 = 56
B = (942639582 DIV 65536) MOD 256 = 14383 MOD 256 = 47
C = (942639582 DIV 256) MOD 256 = 137
D = 942639582 MOD 256 = 22
The resulting number is 56.47.137.222. To check back: A*2^24 + B*2^16 + C*2^8 + D = 56*2^24 + 47*2^16 + 137*2^8 + 222 = 942639582.
Do you have a Python interpreter handy? It's quite easy to write a script to convert between these two formats.
Best regards,
Peter
11-10-2013 02:36 AM
Hi Fabio,
Now, let´s assume I want to define one area with id 259.
This is about integer arithmetics in computers. Notice that a single octet can hold numbers in the range of 0-255. If you want a larger number, you need to use two octets. Here, you can have numbers of the form <0-255>.<0-255> (65536 values in total, 256x256). If you take into account that 255 can be written as 0.255, and 256 is logically 1.0, then 259=256+3=1.3.
When extending it to 4B numbers, this basic principle is retained. Assuming you have an area number N in a linear format, then its dotted decimal format A.B.C.D would be computed as follows:
A = N DIV 2^24
B = (N DIV 2^16) MOD 256
C = (N DIV 2^8) MOD 256
D = N MOD 256
For example, with N = 259:
A = 259 DIV 16777216 = 0
B = (259 DIV 65536) MOD 256 = 0 MOD 256 = 0
C = (259 DIV 256) MOD 256 = 1 MOD 256 = 1
D = 259 MOD 256 = 3
The resulting number is 0.0.1.3. To verify, the linear number should be computed back as A*2^24 + B*2^16 + C*2^8 + D = 0+0+1*256+3 = 259
With N = 942639582:
A = 942639582 DIV 16777216 = 56
B = (942639582 DIV 65536) MOD 256 = 14383 MOD 256 = 47
C = (942639582 DIV 256) MOD 256 = 137
D = 942639582 MOD 256 = 22
The resulting number is 56.47.137.222. To check back: A*2^24 + B*2^16 + C*2^8 + D = 56*2^24 + 47*2^16 + 137*2^8 + 222 = 942639582.
Do you have a Python interpreter handy? It's quite easy to write a script to convert between these two formats.
Best regards,
Peter
11-10-2013 02:47 AM
Hi Peter,
Clear, it make sense.
Thanks!!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide