I have a horrible binary file format, which does have a defined format, and which can contain several odd types of data.
I have loaded the entire file to memory as uint8 data, as the code needs to work on remotely-networked servers, and this is faster than repeated disk accesses.
I have 4 bit, 3 bit, 2 bit and 1 bit integer data fields which may be signed. A single byte can contain two or more fields.
e.g. Field 1: 2 bits, Field 2: 2 bits, Field 3: 4 bits
Currently, for each field, I read the entire byte, right shift it (bitsra) to make the relevant bits the LSB's, use bitand to eliminate the upper, unused bits. If the field is signed, I check the uppermost bit in my valid area, and then set all higher bits equal to the same value using bitor, then I typecast it into int8.
I have a similar process using 2 and 4 bytes for the 24 bit and 12 bit integer fields.
Are there any faster bit operation functions than bitand/bitor/bitsra?

3 件のコメント

dpb
dpb 2013 年 8 月 21 日
編集済み: dpb 2013 年 8 月 21 日
AFAIK, no.
If this is a continuing saga, sounds like mex-file time encapsulated in a class, perhaps.
Obvious application for C struct w/ bitfield and union.
Walter Roberson
Walter Roberson 2013 年 8 月 21 日
If you are doing large numbers of these in the same way, then using vectorized arithmetic operations would probably be faster than the bit* operations.
Iain
Iain 2013 年 8 月 22 日
bitsra is massively slower than the straightforward division I thought it would be faster than. bitand/bitor do seem to be quick.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Computer Vision Toolbox についてさらに検索

質問済み:

2013 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by