转码

问题:

(m & 0x7F) | 0x80) = x ,m >>> 7=y ;
已知x、y,求唯一m=?

注:

scala> 0x80
res0: Int = 128
scala> 0x7F

res1: Int = 127

解:

数据仓库—可爱小猪(1967774718) 17:30:09

y是m的第8位,x是128+m的低七位。 m=y*128+x-128

参考Scala:

def unsignedByteToInt(b: Byte) = b.toInt & 0xFF
def getPid(filename: String,sqlContext: SQLContext) {
    val connection = DriverManager.getConnection("jdbc:mysql://192.168.1.1:3306/db_base?useUnicode=true&characterEncoding=utf8", "root", "123456")
    val statement = connection.createStatement
    val rs: ResultSet = statement.executeQuery("""SELECT type,list FROM table """)
    var count=0
    while (rs.next) {
      count +=1
      val f_type=rs.getLong("type")
      val f_list=rs.getBytes("type")
      println("type:",f_type,"list",f_list.length)
      val bl: Blob = rs.getBlob("f_recommend_list")
      val is: InputStream = bl.getBinaryStream
      //查看blob,可以通过流的形式取出来。
      val buffis: BufferedInputStream = new BufferedInputStream(is)
      //保存到buffout,就工程目录下的filename的文件
      val buf: Array[Byte] = new Array[Byte](1024)
      var len: Int = buffis.read(buf)
        println("lines ,count: ",len,count)
        for (a <- 1 to buf.length-1){
          if (buf(a).toInt >0) {
            var j=1
            buffis.available()
            var id = buf(a).toLong
            while (buf(a-j) < 0 && j<=6 && a-j>0) {
              id = 128 * id + unsignedByteToInt(buf(a-j))-128
              j=j+1
            }
            println("id , j:",id, j) //
          }
        }
      buffis.close()
    }
    rs.last(); //结果集指针指到最后一行数据
    println("rx.len",rs.getRow)
  }


猜你喜欢

转载自blog.csdn.net/u013303361/article/details/80190627