bitsCount

package
v0.0.0-...-1140a65 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package bitsCount counts bits in a integer

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitCount

func BitCount(x uint64) int

BitCount using table lookup, no loop. It is most efficient.

func BitCountByTableLookup

func BitCountByTableLookup(x uint64) int

BitCountByTableLookup Counts number of bits in a 64-bit unsigned integer using table looking using array, approx 30x slower than "BitCount"

Example

ExampleBitCountByTableLookup example counts bits in a 64 bit int using byte lookup table.

const a64bUInt uint64 = 0xC0FFEEBAACE0BABE
a64IntBits := BitCountByTableLookup(a64bUInt)
fmt.Printf("There are %d one-bits in 0x%X\n", a64IntBits, a64bUInt)
Output:

There are 39 one-bits in 0xC0FFEEBAACE0BABE

func BitCountEachOne

func BitCountEachOne(x uint64) int

BitCountEachOne counts number of bits in unsigned integer by iterating over all bits, 2x slower than BitCountByTableLookup

Example

ExampleBitCountEachOne example counts one-bits in a 64 bit int one bit at a time

const a64bUInt uint64 = 0xC0FFEEBAACE0BABE
a64IntBits := BitCountEachOne(a64bUInt)
fmt.Printf("There are %d one-bits in 0x%X\n", a64IntBits, a64bUInt)
Output:

There are 39 one-bits in 0xC0FFEEBAACE0BABE

func InitCli

func InitCli()

InitCli for the "bits" command

eg: the-gpl bits -n=0x1234BAD0 # counts number of 1 bits in n

Types

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

CLI wrapper for *flag.FlagSet

func (CLI) DisplayHelp

func (b CLI) DisplayHelp()

DisplayHelp prints help on command line for bits module

func (CLI) ExecCmd

func (b CLI) ExecCmd(args []string)

ExecCmd run a bit count from CLI

Jump to

Keyboard shortcuts

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