Skip to content

Instantly share code, notes, and snippets.

@msassak
Created February 17, 2011 22:56
Show Gist options
  • Select an option

  • Save msassak/832924 to your computer and use it in GitHub Desktop.

Select an option

Save msassak/832924 to your computer and use it in GitHub Desktop.
The simplest thing that can possibly work.
-module(n2c).
-export([n2c/1]).
n2c("255.255.255.255") -> 32;
n2c("255.255.255.254") -> 31;
n2c("255.255.255.252") -> 30;
n2c("255.255.255.248") -> 29;
n2c("255.255.255.240") -> 28;
n2c("255.255.255.224") -> 27;
n2c("255.255.255.192") -> 26;
n2c("255.255.255.128") -> 25;
n2c("255.255.255.0") -> 24;
n2c("255.255.254.0") -> 23;
n2c("255.255.252.0") -> 22;
n2c("255.255.248.0") -> 21;
n2c("255.255.240.0") -> 20;
n2c("255.255.224.0") -> 19;
n2c("255.255.192.0") -> 18;
n2c("255.255.128.0") -> 17;
n2c("255.255.0.0") -> 16;
n2c("255.254.0.0") -> 15;
n2c("255.252.0.0") -> 14;
n2c("255.248.0.0") -> 13;
n2c("255.240.0.0") -> 12;
n2c("255.224.0.0") -> 11;
n2c("255.192.0.0") -> 10;
n2c("255.128.0.0") -> 9;
n2c("255.0.0.0") -> 8;
n2c("254.0.0.0") -> 7;
n2c("252.0.0.0") -> 6;
n2c("248.0.0.0") -> 5;
n2c("240.0.0.0") -> 4;
n2c("224.0.0.0") -> 3;
n2c("192.0.0.0") -> 2;
n2c("128.0.0.0") -> 1;
n2c("0.0.0.0") -> 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment