I have a file that is a concatenation of K, 17-bit, little endian, unsigned integers. In Matlab I am able to use fread(fd, K, 'bit17', 'ieee-le')
. How do I read 17 bits off of a file descriptor in octave
?
Asked
Active
Viewed 197 times
1

probinso
- 309
- 2
- 9
-
If a file has 48 bits (6 bytes) and you read 17 bits a time, what do you get when you call `fread` a second time? Do you get bits 17-33, or do you get bits 24-40? – carandraug May 29 '18 at 23:19
1 Answers
0
You can read the file byte by byte then use bitget
to get the binary representation of data and then convert the binary representation to decimal numbers.
nbits = 17;
fd = fopen("myfile","rb");
bytes = fread(fd,Inf,"uint8=>uint8");
n = numel(bytes);
bits = false(8, n);
for k = 1:8
bits(k,:)=bitget(bytes,k);
end
count = floor(n * 8/nbits);
val = 2.^(0:nbits-1) * reshape(bits(1:count*nbits),nbits,[]);

rahnema1
- 15,264
- 3
- 15
- 27