[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bit field in file



In article <36bd6b04.0@news.ptt.ru>, "Dmitriy Ryzhov"
<dryzhov@dialup.ptt.ru> wrote:

>Hi
>How i can read file with bit field? I mean most simplest way. In C i use
>structure with bit fields. Is it possible in IDL?
>thanks
>Dmitriy Ryzhov.

There is no sub-byte field in IDL, but you can use the ISHFT command to
extract bits from data. I'm not certain this is exactly what you are
looking for, but I just cleaned up a program that does bit extraction from
data arrays. Select the "bitex" link from
http://www.ivsoftware.com/IV_Code.html and you can get some more info on
it. Here's some usage and examples from it:

usage: subData = BitEx(DataArray, StartBit, NumberBits)
 
BitEx is used to extract a number of bits from an array of data
DataArray is a 1 or more dimensioned array
StartBit is the (0 relative) starting offset bit of the array
NumberBits is the number of bits to extract from the array
    starting from the StartBit position within the array
The returned value will be an unsigned data type capable of
    storing NumberBits. For example, If 8 < NumberBits <= 16,
    subData will be an unsigned int. subData will be a Byte if
    8 or less bytes are specified by NumberBits.
 
Examples:
aData = [15b, 63b, 127b, 191b, 31b]
Help, BitEx(aData, 0, 8)
<Expression>    BYTE      =   15
Help, BitEx(aData, 8, 8)
<Expression>    BYTE      =   63
Help, BitEx(aData, 4, 8)
<Expression>    BYTE      =  243
Help, BitEx(aData, 0, 16)
<Expression>    UINT      =     3903
aData = [511, 8192]
Help, BitEx(aData, 8, 16)
<Expression>    UINT      =    65312
Help, BitEx(aData, 4, 24)
<Expression>    ULONG     =      2093568

-- 
Mike Schienle                                 Interactive Visuals, Inc.
mgs@ivsoftware.com                           http://www.ivsoftware.com/