Questions tagged [bit-packing]

Use this tag for questions related to bit packing, for example packing bits into integer types.

is used in its general concept, and is usually found in questions using C (or C based languages) or Java.

64 questions
1
vote
2 answers

Bitwise packing/unpacking - generalized solution for arbitrary values

I'm trying to adapt this answer to arbitrary numeric values. Let's say we have 3 (unsigned) numbers: v1, v2, v3 and we know the respective max values they may have: max1, max2, max3. max1 * max2 * max3 < 2^32, so the result (packed value) is to be…
hindmost
  • 7,125
  • 3
  • 27
  • 39
1
vote
1 answer

Shift byte value into int

I am attempting to store a single byte value into a position within an int, however, I am having trouble figuring out how this would be done. I have shifted the byte that i want to store in the int to the correct value, but I am at a loss as to how…
jordan t
  • 136
  • 10
1
vote
1 answer

Is there a standard, how to pack non-byte-aligned bits in big endian?

I have a storage of n bytes (in my case a QByteArray in Qt, but i think the question is more a general question). I have a class that operates on that storage and stores different kind of data types at any bit position in that bit field. It does…
1
vote
1 answer

Extract 10bits words from bitstream

I need to extract all 10-bit words from a raw bitstream whitch is built as ABACABACABAC... It already works with a naive C implementation like for(uint8_t *ptr = in_packet; ptr < max; ptr += 5){ const uint64_t val = (((uint64_t)(*(ptr +…
poypoy
  • 133
  • 1
  • 7
1
vote
1 answer

Optimizing Matrix multiplication in C with Bit Packing

I'm currently attempting to write an algorithm for optimizing matrix multiplication over GF(2) using bit-packing. Both matrices A and B are provided in column major order so I start by copying A into row-major order and then packing the values into…
KONADO
  • 189
  • 1
  • 13
1
vote
2 answers

How do I pack bits from one byte array to another efficiently in python3?

I have a fairly large byte array in python. In the simplest situation the byte array only contains 0 or 1 values (0x00, 0x01), also the array is always a multiple of 8 in length. How can I pack these "bits" into another byte array (it doesn't need…
Robotbugs
  • 4,307
  • 3
  • 22
  • 30
1
vote
0 answers

Does LZ4 compression eliminate the need for manual bit packing?

I'm considering using LZ4 compression for a high bandwidth browser game I'm developing. I'm currently pre-compressing 1000s of float32 values down to 16bits. I'm wondering if I pre-compressed down to 12bits but saved those values as uint16s, whether…
Mischawaka
  • 225
  • 2
  • 10
1
vote
1 answer

Taking OpenCV Mat and converting to array of 12bit values.

I have an cv::Mat of doubles image that I've truncated between 0.0 and 4095.0. I want to be able to convert this matrix/create a new matrix based on this one that is 12bit. (smallest int size needed to hold 0 -> 4095 integer values). I can just get…
Krupip
  • 4,404
  • 2
  • 32
  • 54
1
vote
3 answers

jquery SMS character calculator with 7-bit and 16bit

I have a text field to type sms message both in english and chinese language. As I have searched, 1 sms can only have 1120 bits. Each english character is 7 bit so it can be 1120/7 = 160 characters and for chinese each character is 16 bits so that…
Manas
  • 3,060
  • 4
  • 27
  • 55
1
vote
1 answer

Why does packing not work across sibling unions or structs

In the following example I expect the size of complex_t to be the same as uint16_t: 2 bytes, however it's 3 bytes. Removing the second union ("proximity_unsafe") reduces the size to 2 bytes, but I can't figure out the model of the packing…
Catskul
  • 17,916
  • 15
  • 84
  • 113
1
vote
1 answer

Pack a number into an odd number of bits

2 header field that is 19 bits long. I'm trying to pack the number 921 decimal into hex into it. Least Significant Byte first. Packing into 24 bits is easy: 921.0 = 0x0399 binary: 9 9 0 3 0 0 1001 1001 0000 0011 0000 0000 and done.…
dlite922
  • 1,924
  • 3
  • 24
  • 60
1
vote
4 answers

How to override C compiler aligning word-sized variable in struct to word boundary

I have a structure specified as following Member 1, 16 bits Member 2, 32 bits Member 3, 32 bits which I shall be reading from a file. I want to read straight from the file into the struct. The problem is that the C compiler will align the…
TSG
  • 877
  • 1
  • 6
  • 23
1
vote
2 answers

How to pack bit fields in short integer with a char array?

In the following 2 structures, typedef struct _a { short a1:13 __attribute__((packed)); char a2[4] __attribute__((packed)); } a; typedef struct _b { short b1:10 __attribute__((packed)); short b2:10 __attribute__((packed)); …
badmad
  • 2,059
  • 2
  • 14
  • 14
0
votes
1 answer

Problems with bit-packing and dynamically allocating

Im having trouble with this piece of code. Im building an image encoder. Basically I built an encoding array using values from the image. The array is called 'codes', and stores char* representations of what the binary values will be. This section…
Nick Schudlo
  • 301
  • 3
  • 4
  • 12
0
votes
0 answers

How can I generate a Parquet file with bit-packed encoding rep/def levels?

I know this encoding is Deprecated, but I want to test the correctness of my Parquet reader, but I can't produce this file now. Is there any way to generate bit-packed encoding rep/def levels parquet file?
Smith Cruise
  • 404
  • 1
  • 4
  • 19