---
name: "gbits.c"
section: "3"
platform: "linux"
package: "libg2c-dev"
version: "2.1.0-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/gbits.c"
---

# gbits.c(3)

Functions to pack and unpack bits to/from a packed bit string.

## NAME

gbits.c - Functions to pack and unpack bits to/from a packed bit string.

## SYNOPSIS

`#include 'grib2_int.h'`\

### Functions

void **g2c\_gbit\_int** (unsigned char \*in, int \*iout, int iskip, int nbits)\
 Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.  int **g2c\_gbits\_int** (unsigned char \*in, int \*iout, int iskip, int nbits, int nskip, int n)\
 Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.  void **gbit** (unsigned char \*in, **g2int** \*iout, **g2int** iskip, **g2int** nbits)\
 Get arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.  void **gbits** (unsigned char \*in, **g2int** \*iout, **g2int** iskip, **g2int** nbits, **g2int** nskip, **g2int** n)\
 Unpack arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.  void **sbit** (unsigned char \*out, **g2int** \*in, **g2int** iskip, **g2int** nbits)\
 Store arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.  void **sbits** (unsigned char \*out, **g2int** \*in, **g2int** iskip, **g2int** nbits, **g2int** nskip, **g2int** n)\
 Store arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.

## Detailed Description

Functions to pack and unpack bits to/from a packed bit string.

**Author**

NOAA Programmer

Definition in file **gbits.c**.

## Function Documentation

### void g2c\_gbit\_int (unsigned char \* in, int \* iout, int iskip, int nbits)

Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. This is similar to **gbit()**, but with int types instead of g2int.

**Parameters**

*in* pointer to character array input. \
 *iout* pointer that gets the unpacked array output. \
 *iskip* initial number of bits to skip. \
 *nbits* number of bits to take.

**Author**

NOAA Programmer

Definition at line **113** of file **gbits.c**.

References **g2c\_gbits\_int()**.

### int g2c\_gbits\_int (unsigned char \* in, int \* iout, int iskip, int nbits, int nskip, int n)

Extract arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array. This is similar to **gbits()**, but with int types instead of g2int.

**Parameters**

*in* Pointer to character array input. \
 *iout* Pointer that gets the unpacked array output. \
 *iskip* Initial number of bits to skip. \
 *nbits* Number of bits to take. \
 *nskip* Additional number of bits to skip on each iteration. \
 *n* Number of iterations.

**Returns**

- •

  **G2C\_NOERROR** No error.

- •

  **G2C\_ENOMEM** Out of memory.

**Author**

Ed Hartnett

**Date**

8/31/22

Definition at line **137** of file **gbits.c**.

References **G2C\_EINVAL**, **G2C\_ENOMEM**, **G2C\_NOERROR**, and **gbits()**.

Referenced by **g2c\_gbit\_int()**.

### void gbit (unsigned char \* in, g2int \* iout, g2int iskip, g2int nbits)

Get arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.

**Parameters**

*in* pointer to character array input. \
 *iout* pointer that gets the unpacked array output. \
 *iskip* initial number of bits to skip. \
 *nbits* number of bits to take.

**Author**

NOAA Programmer

Definition at line **20** of file **gbits.c**.

References **gbits()**.

Referenced by **comunpack()**, **g2\_addfield()**, **g2\_addgrid()**, **g2\_addlocal()**, **g2\_getfld()**, **g2\_gribend()**, **g2\_info()**, **g2\_unpack1()**, **g2\_unpack2()**, **g2\_unpack3()**, **g2\_unpack4()**, **g2\_unpack5()**, **g2\_unpack6()**, **g2c\_check\_msg()**, **g2c\_unpack7\_int()**, and **seekgb()**.

### void gbits (unsigned char \* in, g2int \* iout, g2int iskip, g2int nbits, g2int nskip, g2int n)

Unpack arbitrary size values from a packed bit string, right justifying each value in the unpacked iout array.

**Parameters**

*in* Pointer to character array input. \
 *iout* Pointer that gets the unpacked array output. \
 *iskip* Initial number of bits to skip. \
 *nbits* Number of bits to take. \
 *nskip* Additional number of bits to skip on each iteration. \
 *n* Number of iterations.

**Author**

NOAA Programmer

Definition at line **57** of file **gbits.c**.

Referenced by **aecunpack\_int()**, **comunpack()**, **g2\_unpack3()**, **g2\_unpack4()**, **g2\_unpack6()**, **g2c\_gbits\_int()**, **gbit()**, **pngunpack\_int()**, **simunpack()**, and **specunpack()**.

### void sbit (unsigned char \* out, g2int \* in, g2int iskip, g2int nbits)

Store arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.

**Parameters**

*out* Pointer to packed array output. Must be allocated large enough to hold output. \
 *in* Pointer that gets the unpacked array input. \
 *iskip* Initial number of bits to skip. \
 *nbits* Number of bits to pack.

**Author**

NOAA Programmer

Definition at line **38** of file **gbits.c**.

References **sbits()**.

Referenced by **compack()**, **g2\_addfield()**, **g2\_addgrid()**, **g2\_addlocal()**, **g2\_create()**, **g2\_gribend()**, **misspack()**, and **simpack()**.

### void sbits (unsigned char \* out, g2int \* in, g2int iskip, g2int nbits, g2int nskip, g2int n)

Store arbitrary size values into a packed bit string, taking the low order bits from each value in the unpacked array.

**Parameters**

*out* Pointer to packed array output. Must be allocated large enough to hold output. \
 *in* Pointer that gets the unpacked array input. \
 *iskip* Initial number of bits to skip. \
 *nbits* Number of bits to pack. \
 *nskip* Additional number of bits to skip on each iteration. \
 *n* Number of iterations.

**Author**

NOAA Programmer

Definition at line **178** of file **gbits.c**.

Referenced by **aecpack\_int()**, **compack()**, **g2\_addfield()**, **g2\_addgrid()**, **jpcpack\_int()**, **misspack()**, **pngpack\_int()**, **sbit()**, and **simpack()**.

## Author

Generated automatically by Doxygen for NCEPLIBS-g2c from the source code.
