[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fread and ubit1
From: |
Jaroslav Hajek |
Subject: |
Re: fread and ubit1 |
Date: |
Wed, 15 Sep 2010 09:58:17 +0200 |
On Tue, Sep 14, 2010 at 11:56 PM, drumaliens <address@hidden> wrote:
>
> In MATLAB I can read in just 1 bit from a binary file using bit1. In octave I
> can't.
>
> The only way I can think of get round this is to read in an int8, say, see
> if it is greater than 127 which will give a 1 for the MSB and then make use
> of fseek to move back by 7 bits. (Must admit haven't tried this)
>
> Is there any more elegent way of doing this ?
>
> Thanks
>
AFAIK, the smallest unit of binary reading supported by all OSes I
know is a byte. To get bits, just read bytes and decompose them to
bits. In Octave 3.3.52+, this can be conveniently done by bitunpack:
octave:1> bitunpack (uint8(129))
ans =
1 0 0 0 0 0 0 1
bitpack can be used to pack the logical array back into bytes/words/dwords.
hth
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- fread and ubit1, drumaliens, 2010/09/14
- Re: fread and ubit1,
Jaroslav Hajek <=