go-xim/compile.go

32 lines
621 B
Go
Raw Normal View History

2021-11-08 05:10:49 +00:00
package xim
2021-11-07 07:56:21 +00:00
const (
maxbitwidth = 64
)
const (
2021-11-09 00:27:21 +00:00
maskunixtime = 0b0111111111111111111111111111111111111111000000000000000000000000
maskchaos = 0b0000000000000000000000000000000000000000111111111111111111111111
2021-11-07 07:56:21 +00:00
)
const (
widthfirst = 40
widthsecond = maxbitwidth - widthfirst
)
func compile(first uint64, second uint64) uint64 {
2021-11-09 00:27:21 +00:00
var compiled uint64 = ((first << widthsecond) & maskunixtime) | (second & maskchaos)
2021-11-07 07:56:21 +00:00
return compiled
}
func decompile(value uint64) (uint64, uint64) {
2021-11-09 00:27:21 +00:00
var first uint64 = (value & maskunixtime) >> widthsecond
var second uint64 = value & maskchaos
2021-11-07 07:56:21 +00:00
return first, second
}