GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
pack_k_bits.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GR_BLOCKS_PACK_K_BITS_H
12 #define INCLUDED_GR_BLOCKS_PACK_K_BITS_H
13 
14 #include <gnuradio/blocks/api.h>
15 #include <vector>
16 
17 namespace gr {
18 namespace blocks {
19 namespace kernel {
20 
21 /*!
22  * \brief Converts a vector of bytes with 1 bit in the LSB to a
23  * byte with k relevant bits.
24  *
25  * Example:
26  * k = 4
27  * in = [0,1,0,1, 0x81,0x00,0x00,0x00]
28  * out = [0x05, 0x08]
29  *
30  * k = 8
31  * in = [1,1,1,1, 0,1,0,1, 0,0,0,0, 1,0,0,0]
32  * out = [0xf5, 0x08]
33  * \ingroup byte_operators_blk
34  */
36 {
37 public:
38  /*!
39  * \brief Make a pack_k_bits object.
40  * \param k number of bits to be packed.
41  */
42  pack_k_bits(unsigned k);
44 
45  /*!
46  * \brief Perform the packing.
47  *
48  * This block performs no bounds checking. It assumes that the
49  * input, \p in, has of length k*nbytes and that the output
50  * vector, \p out, has \p nbytes available for writing.
51  *
52  * \param bytes output vector (k-bits per byte) of the unpacked data
53  * \param bits The input vector of bits to pack
54  * \param nbytes The number of output bytes
55  */
56  void pack(unsigned char* bytes, const unsigned char* bits, int nbytes) const;
57 
58  /*!
59  * Same as pack() but reverses the bits.
60  */
61  void pack_rev(unsigned char* bytes, const unsigned char* bits, int nbytes) const;
62 
63  int k() const;
64 
65 private:
66  unsigned d_k;
67 };
68 
69 } /* namespace kernel */
70 } /* namespace blocks */
71 } /* namespace gr */
72 
73 #endif /* INCLUDED_GR_BLOCKS_PACK_K_BITS_H */
Converts a vector of bytes with 1 bit in the LSB to a byte with k relevant bits.
Definition: pack_k_bits.h:36
pack_k_bits(unsigned k)
Make a pack_k_bits object.
void pack_rev(unsigned char *bytes, const unsigned char *bits, int nbytes) const
void pack(unsigned char *bytes, const unsigned char *bits, int nbytes) const
Perform the packing.
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29