Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# Bit packing of array of integers

By : dkd
Date : October 14 2020, 11:12 PM
may help you . I agree with keraba that you need to use something like Huffman coding or perhaps the Lempel-Ziv-Welch algorithm. The problem with bit-packing the way you are talking about is that you have two options:
Pick a constant n such that the largest integer can be represented. Allow n to vary from value to value.
code :

Share :

## Packing 4 Integers as ONE BYTE?

By : user2836616
Date : March 29 2020, 07:55 AM
it helps some times Use shift and bitwise OR, then convert to a character to get a "byte":
code :
x = chr(a | (b << 1) | (c << 2) | (d << 5))
i = ord(x)
a = i & 1
b = (i >> 1) & 1
c = (i >> 2) & 7
d = (i >> 5) & 7
0000000a
0000000b
00000ccc
00000ddd
0000000a
000000b0
000ccc00
ddd00000
dddcccba
dddcccba
0dddcccb
00dddccc
00000ddd
0000000a
0000000b
00000ccc
00000ddd

## Packing 4 Integers as ONE INTEGER?

By : user2836696
Date : March 29 2020, 07:55 AM
hop of those help? Equivalently to my previous answer, but using * and + instead of << and |, you can do
code :
i = a + 2*b + 4*c + 32*d
a, b, c, d = i % 2, i//2 % 2, i//4 % 8, i//32 % 8

## Packing 4 integers into one single [10,10,10,2] integer

Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The unsigned right shift operator >>> shifts a zero into the leftmost position.
Source: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html

## Packing sets of non power of 2 integers

By : Alexey
Date : March 29 2020, 07:55 AM
should help you out I have a set of integers, each with a specific range: , A list of variables with different ranges like this:
code :
foo = [1, 5]
bar = [1, 10]
baz = [1, 200]
packed = (foo - 1) + 5 * (bar - 1) + (5 * 10) * (baz - 1)
// extract foo
foo = packed % 5 + 1
// drop foo from packed representation
packed /= 5
// extract bar (which is now the lowest digit in 'packed')
bar = packed % 10 + 1
// drop bar
packed /= 10
// top digit is left over
baz = packed + 1

## Efficient packing bytes into Integers?

By : Prof. CAJ Herkstrote
Date : March 29 2020, 07:55 AM
seems to work fine I would look at the binary package for efficiently packing and unpacking binary data structures: