Add HasBitFlag, SetBitFlag, UnSetBitFlag
This commit is contained in:
parent
8716d301c6
commit
9823133648
42
sysutils.go
42
sysutils.go
@ -1,18 +1,18 @@
|
|||||||
package q5
|
package q5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"net"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
"io/ioutil"
|
|
||||||
"reflect"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDaySeconds(seconds int64, timeZone int64) int64 {
|
func GetDaySeconds(seconds int64, timeZone int64) int64 {
|
||||||
return ((seconds + timeZone * 3600)/3600/24 + 1) * 3600 * 24 - 3600 * timeZone;
|
return ((seconds+timeZone*3600)/3600/24+1)*3600*24 - 3600*timeZone
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTickCount() int64 {
|
func GetTickCount() int64 {
|
||||||
@ -130,3 +130,29 @@ func FormatUnixDateEx(sec int64) string {
|
|||||||
strTime := time.Unix(sec, 0).Format("20060102")
|
strTime := time.Unix(sec, 0).Format("20060102")
|
||||||
return strTime
|
return strTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxBitNum = 63 // 最大的有效位号,根据 int64 的位宽确定
|
||||||
|
)
|
||||||
|
|
||||||
|
func HasBitFlag(val int64, bitNum int32) bool {
|
||||||
|
if bitNum < 0 || bitNum > maxBitNum {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
mask := int64(1) << bitNum
|
||||||
|
return (val & mask) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetBitFlag(val *int64, bitNum int32) {
|
||||||
|
if bitNum < 0 || bitNum > maxBitNum {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*val |= int64(1) << bitNum
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnSetBitFlag(val *int64, bitNum int32) {
|
||||||
|
if bitNum < 0 || bitNum > maxBitNum {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*val &= ^(int64(1) << bitNum)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user