github.com/whatap/golib@v0.0.22/util/bitutil/BitUtil.go (about)

     1  package bitutil
     2  /*
     3    TODO : 검증 테스트해야함.
     4  */
     5  func Composite64(hkey, wkey int32) int64 {
     6  	return (int64(hkey) << 32) | (int64(wkey) & 0xffffffff)
     7  }
     8  func Composite32(hkey, wkey int16) int32 {
     9  	return (int32(hkey) << 16) | (int32(wkey) & 0xffff)
    10  }
    11  func Composite16(hkey, wkey byte) int16 {
    12  	return (int16(hkey) << 8) | (int16(wkey) & int16(0xff))
    13  }
    14  
    15  func SetHigh64(src int64, hkey int32) int64 {
    16  	return (src & 0x00000000ffffffff) | (int64(hkey) << 32)
    17  }
    18  func SetLow64(src int64, wkey int32) int64 {
    19  	var x uint64 = 0xffffffff00000000
    20  	return (src & int64(x)) | (int64(wkey) & 0xffffffff)
    21  }
    22  func GetHigh64(key int64) int32 {
    23  	var x uint32 = 0xffffffff
    24  	return int32(key>>32) & int32(x)
    25  }
    26  func GetLow64(key int64) int32 {
    27  	var x uint32 = 0xffffffff
    28  	return int32(key) & int32(x)
    29  }
    30  func GetHigh32(key int32) int16 {
    31  	var x uint16 = 0xffff
    32  	return int16(key >> 16) & int16(x)
    33  }
    34  func GetLow32(key int32) int16 {
    35  	return int16(key & 0xffff)
    36  }
    37  
    38  func GetHigh16(key int16) byte {
    39  	return byte((key >> 8) & int16(0xff))
    40  }
    41  func GetLow16(key int16) byte {
    42  	return byte(key & int16(0xff))
    43  }