# Javascript int 与 4 位 byte 互转

📆 2021-12-14 13:25

# int 转 4 位 byte

function int_to_byte4(source) {
  var target=[]
  target[3]=source&0xFF
  target[2]=source>>8&0xFF
  target[1]=source>>16&0xFF
  target[0]=source>>24&0xFF
  return target
}

# 4 位 byte 转 int

function byte4_to_int(source){
  var target=0
  target+=source[3]&0xFF
  target+=(source[2]&0xFF)<<8
  target+=(source[1]&0xFF)<<16
  target+=(source[0]&0xFF)<<24
  return target
}
最后更新于: 8/16/2022, 2:48:47 PM