2 ms·
I'm bad at math. What's the algorithm for this? Something about 256^(1..4)?
by 90s_dev 1y ago
I'm bad at math. What's the algorithm for this? Something about 256^(1..4)?
- davejagoda 1y agoecho 256^3+256^2+256^1+256^0|bc 16843009
- 90s_dev 1y agoHa, then I was right, but with a one-off error!
- hug 1y agoIPs are 4 octets, normally represented as a decimal between 0 and 255, or 00000000 and 1111111 in binary. Remove the dots and concat the binary value for 1.1.1.1 and you get 00000001000000010000000100000001. Convert that binary value to decimal and you get 16843009.
- opello 1y agoYou can think about it like the IP address in hex if you like: 0x01.0x01.0x01.0x01 becomes 0x01010101 which is 16,843,009. So the first 0x01 is 0x01000000 which is the familiar 16,777,216 which then gets the further "base 256 digits" added to it. Or maybe in your terms it's 256^(0..3) where you can think of it like each dotted component is a symbol (like 0-9 in base 10) where each component is a position digit. Where the right-most element is the "256^0" ("ones") digit, and the left most element is the "256^3" ("16,777,216s") digit.