Filter löschen
Filter löschen

conversion of decimal number matrix into binary matrix using optimal bit length

2 Ansichten (letzte 30 Tage)
how to convert decimal numbers into binary in a matrix column wise with user defined bits?
  15 Kommentare
Walter Roberson
Walter Roberson am 1 Mai 2019
What was your plan in decoding this? You can create a row-by-row vector of bits easily enough, but to decode you have to know one of a small number of things:
  1. a row-by-row list of sizes for each element, probably encoded in binary. If you were to keep such a row-by-row list then you might as well use just enough bits needed to encode the value. Except for the case of 0 itself, you could use a hidden-bit algorithm. For example if you know that you need 3 bits to represent 5, binary [1 0 1], then if you have that "3" stored, you can omit the leading 1 because for any value other than 0, the leading bit for minimum representation will always be a 1. So you could store "3" and [0 1]. The number of bits required to store the length would be 0 (for 0) to 4 (8 itself needs 4 bits). WIth the number of bits for the length being variable, you have to consider whether you want to use some kind of variable bits scheme to encode the length, or if you want to use a fixed width.If you use a fixed width, that would add 4 bits per element, making it 4 bits (for 0) to 12 bits (for 128 to 255). You should be asking yourself what your average cost of representation would be in such a system.; OR
  2. Separately, keep a column by column list of sizes of the secondary widths, along with a per-column row number of which row the maximum occurred at (the one that the full 8 bits was used for.)The secondary widths could be 0 (for 0) to 8 (for 128 to 255), requiring 0 to 4 bits per column. If you used a fixed-width scheme, you could pack the widths for C columns into C/2 8-bit bytes. Then you would need C rows numbers to indicate where the maxima occurs. The number of bits needed to represent the row numbers depends upon how many rows there were in the table. Total space for this information would be ceiling(log2(number_of_rows)) * number_of_columns; OR
  3. Instead of keeping a list of row numbers for each column, each entry could be preceeded by a bit that indicates whether it is full width or the column-specific narrower width. Total space for this information over the entire table would be 1 (bit) * number_of_rows * number_of_columns. However, this setup permits you to partition the column entries into "needs 8 bits" and "needs fewer than 8 bits". For example if the rows contained 197 and 183 and 29 and 5 and 17, then with your existing scheme, the maximum one, 197, would be allocated 8 bits, and all other entries in the column would be allocated the number of bits required to store the second largest, 183, which would also be 8 bits, and therefore all entries in the row would end up as 8 bits. If you partitioned into "needs 8 bits" vs "not", then the 197 and 183 would both need 8 bit, and the width for the remaining entries would be determined by the maximum of the remaining values, 29, so only 5 bits each would be needed for those rather than 8.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by