How to read in a file in its bit representation

36 vues (au cours des 30 derniers jours)
Florian
Florian le 13 Avr 2013
Hi everyone,
I was wondering whether I can read in any file from disk in its binary representation, so in its representation of "0"s and "1"s as it is stored on my disk.
Although I thought this may be trivial, I can only find commands for reading in data itself stored in some given format.
Can anyone help?
All the best to you Matlab wizards, Florian

Réponse acceptée

Image Analyst
Image Analyst le 13 Avr 2013
You can use fread() to read in a file as bytes. Of course each byte is comprised of 0's and 1's. There is no "bit" data class in MATLAB - the bytes is the smallest. If you want, you can extract each 0 or 1 from a byte into 8 byte array, such as an array of uint8 or char, but that' just increases the storage by a factor of 8, though you do get each 0 and 1 just by itself.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 13 Avr 2013
bits = fread(fid, '*ubit1', 'ieee-le');
Adjust the 'ieee-le' to 'ieee-be' if you prefer (this controls whether the bits will be output from least significant first or from most significant first)

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by