# Class Uint32Bits

Provides methods to manipulate and read individual and bits in the numbers held by a a typed array `Uint32Array`.

##### Index

### Constructors

constructor

### Properties

data

### Accessors

bytes
dataOffset
isChanged
value

### Methods

getNumber
has
off
on
set
setNumber
toBinaryString
getNumber
has
mask
off
on
set
setNumber
toBinaryString

## Constructors

### constructor

- new Uint32Bits(
  data: Pick<
  LazyResizableTypedArray<number, Uint32Array>,
  "buffer" | "uint8",
  >,
  _onValueChanged?: Uint32BitsOnChangedEventHandler,
  ): Uint32Bits

  constructor

  #### Parameters

  - data: Pick<LazyResizableTypedArray<number, Uint32Array>, "buffer" | "uint8">

    uint32 numbers to read/manipulate

  - _onValueChanged: Uint32BitsOnChangedEventHandler = ...

    Callback which is invoked when a value has changed.

  #### Returns Uint32Bits

## Properties

### `Readonly` data

data: Pick<LazyResizableTypedArray<number, Uint32Array>, "buffer" | "uint8">

uint32 numbers to read/manipulate

## Accessors

### bytes

- get bytes(): Uint32Bytes

  Get a Uint32Bytes instance that can be used to manipulate the number that the bytes in data.`buffer` represents. The number is specified by setting dataOffset. Calling mutating methods in the Uint32Bytes will trigger the _onValueChanged callback. and isChanged will also be changed accordingly.

  #### Returns Uint32Bytes

### dataOffset

- get dataOffset(): number

  Gets the offset of the number in data the Uint32Bits instance is working with

  #### Returns number

- set dataOffset(o: number): void

  Sets the offset of the number in data the Uint32Bits instance is working with, Also resets the isChanged property to false.

  #### Parameters

  - o: number

  #### Returns void

### isChanged

- get isChanged(): boolean

  Whether the number in data that dataOffset currently points to has changed since dataOffset was last called. Can only be changed by calling methods and properties on this Uint32Bits instance.

  #### Returns boolean

### value

- get value(): number

  The `uint32` number that the Uint32Bits instance is currently working with (specified by dataOffset).

  #### Returns number

- set value(v: number): void

  Replace the `uint32` number in data that dataOffset points to. Will trigger _onValueChanged callback and isChanged will also be changed accordingly.

  #### Parameters

  - v: number

  #### Returns void

## Methods

### getNumber

- getNumber(bit: BitIndex, size: number): number

  Returns the number stored at a `bit` up to the bit specified by `bit` + `size`.

  #### Parameters

  - bit: BitIndex

    bit

  - size: number

    number of bits starting at `bit`.

  #### Returns number

  The number stored at `[bit, bit + size]`.

### has

- has(bit: BitIndex): boolean

  Check if a bit is on or off in data [dataOffset].

  #### Parameters

  - bit: BitIndex

    The bit to check-

  #### Returns boolean

  `true` if bit is on. Otherwise `false`.

### off

- off(bit: BitIndex): Uint32Bits

  Sets a bit to 0 in data [dataOffset].

  #### Parameters

  - bit: BitIndex

    Bit to set to on/off

  #### Returns Uint32Bits

  The current Uint32Bits instance.

### on

- on(bit: BitIndex): Uint32Bits

  Sets a bit to 1 in data [dataOffset].

  #### Parameters

  - bit: BitIndex

    Bit to set to on/off

  #### Returns Uint32Bits

  The current Uint32Bits instance.

### set

- set(bit: BitIndex, truthy: unknown): Uint32Bits

  Set a bit to on/off in data[dataOffset].

  #### Parameters

  - bit: BitIndex

    Bit to set on/off.

  - truthy: unknown

    `truthy` sets the bit 1. `falsy` sets it to 0.

  #### Returns Uint32Bits

  The current Uint32Bits instance.

### setNumber

- setNumber(bit: BitIndex, size: number, val: number): Uint32Bits

  Store a number at bits defined by `bit` and `bit + size`. Only the first size bits of `val` will be used.

  #### Parameters

  - bit: BitIndex

    bit to start storing `val` at.

  - size: number

    number of bits to store `val` at.

  - val: number

    Value to store

  #### Returns Uint32Bits

  The Uint32Bits instance. Useful for chaining.

### toBinaryString

- toBinaryString(): string

  Converts data[dataOffset] to a binary string

  #### Returns string

  Binary string representation (32 positions.)

### `Static` getNumber

- getNumber(value: number, bit: BitIndex, size: number): number

  Returns the number stored at a specified bit up to the bit specified by `bit + size`.

  #### Parameters

  - value: number

    The value to extract the number from.

  - bit: BitIndex

    The starting bit position.

  - size: number

    The number of bits to extract.

  #### Returns number

  The number stored at [bit, bit + size].

### `Static` has

- has(value: number, bit: BitIndex): boolean

  Checks if a bit is on or off in the given value.

  #### Parameters

  - value: number

    The value to check.

  - bit: BitIndex

    The bit to check.

  #### Returns boolean

  `true` if the bit is on, otherwise `false`.

### `Static` mask

- mask(bit: BitIndex, size: number): number

  Creates a mask with bits specified by `bit` to `bit + size` set to 1. All other bits are 0

  #### Parameters

  - bit: BitIndex

    bit

  - size: number

    number of bits to set

  #### Returns number

  mask

### `Static` off

- off(value: number, bit: BitIndex): number

  Sets a bit to 0 in the given value.

  #### Parameters

  - value: number

    The original value.

  - bit: BitIndex

    The bit to set to 0.

  #### Returns number

  The modified value with the bit set to 0.

### `Static` on

- on(value: number, bit: BitIndex): number

  Sets a bit to 1 in the given value.

  #### Parameters

  - value: number

    The original value.

  - bit: BitIndex

    The bit to set to 1.

  #### Returns number

  The modified value with the bit set to 1.

### `Static` set

- set(value: number, bit: BitIndex, truthy: unknown): number

  Sets a bit to on/off in the given value.

  #### Parameters

  - value: number

    The original value.

  - bit: BitIndex

    The bit to set on/off.

  - truthy: unknown

    `truthy` sets the bit to 1, `falsy` sets it to 0.

  #### Returns number

  The modified value with the bit set.

### `Static` setNumber

- setNumber(value: number, bit: BitIndex, size: number, val: number): number

  Stores a number at bits defined by `bit` and `bit + size`. Only the first size bits of `val` will be used.

  #### Parameters

  - value: number

    The original value.

  - bit: BitIndex

    The starting bit position.

  - size: number

    The number of bits to store.

  - val: number

    The value to store.

  #### Returns number

  The modified value with the number stored at the specified bits.

### `Static` toBinaryString

- toBinaryString(n: number): string

  converts `n` to a binary string

  #### Parameters

  - n: number

    Number to convert to a binary string.

  #### Returns string

  Binary string representation (32 positions.)