用Spark将IP地址转换成十进制,希望对大家有用.
//定义一个方法:将IP转换成十进制 def ipLongs(ip: String): Long = { //将IP地址按照"."进行切分 val fragments = ip.split("[.]") var ipNum = 0L //位移运算:左移 for (i <- 0 until fragments.length){ ipNum = fragments(i).toLong | ipNum << 8L } ipNum }
用Spark将IP地址转换成十进制,希望对大家有用.
//定义一个方法:将IP转换成十进制 def ipLongs(ip: String): Long = { //将IP地址按照"."进行切分 val fragments = ip.split("[.]") var ipNum = 0L //位移运算:左移 for (i <- 0 until fragments.length){ ipNum = fragments(i).toLong | ipNum << 8L } ipNum }