snippets

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T interface {
	constraints.Signed | constraints.Float
}](x T) T

func BitwiseClear

func BitwiseClear(a *int, x int)

按位清零

func BitwiseTo1

func BitwiseTo1(a *int, x int)

按位赋1

func CountBit1

func CountBit1(a int) uint8

使用 n&(n-1) 计算二进制1的个数, 可参考下图 ![20220428104951](https://raw.githubusercontent.com/lich-Img/blogImg/master/img/20220428104951.png)

func Last1

func Last1(a int) int

使用n&(-n)获取二进制最后一位1 应用:判断一个数是否是2的幂

func solution(x int) bool {
		return n>0&(n&(-n))==n
}

func MaxN

func MaxN[T constraints.Ordered](vars ...T) T

func MinN

func MinN[T constraints.Ordered](vars ...T) T

func PickBit

func PickBit(a int, x int) uint8

取某一位的值

func ReversionBit

func ReversionBit(a *uint16)

反转位,如对uint16反转前8位

func SameSign

func SameSign(a, b int) bool

检查符号是否相同

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL