Created
June 22, 2011 16:23
-
-
Save CerebralMastication/1040479 to your computer and use it in GitHub Desktop.
convert IP address to integer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ip2Int <- function(ip){ | |
split <- as.numeric(strsplit(ip, "\\.")[[1]]) | |
out <- (split[1] * 256^3) + (split[2] * 256^2) + (split[3] * 256) + (split[4]) | |
return(out) | |
} | |
int2Ip <- function(int){ | |
split <- NULL | |
split[1] <- as.integer(int/256^3) | |
int <- int - split[1] * (256^3) | |
split[2] <- as.integer(int/256^2) | |
int <- int - split[2] * (256^2) | |
split[3] <- as.integer(int/256) | |
int <- int - split[3] * 256 | |
split[4] <- int | |
return(paste(split, collapse = ".")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment