Reading 12 bit integers from file

I am new to Julia and trying to port some code from Matlab. I have an image file saved as a raw binary file with 12 bit precision. In Matlab I can use fread (Read data from binary file - MATLAB fread - MathWorks United Kingdom):

A = fread(fileID, sizeA, precision) with precision equal to 12.

In julia, I can only find methods that support a precision which is a multiple of 8. Are there any methods available?

I guess you should read 24 bits at a time and split them up.


Welcome to our community :confetti_ball:

uhhh, in the documentation link you gave 12 is not a valid precision, there is ubit12 and bit12 what one did you use? Did you have negative numbers?


Thanks! I figured this might be the way to go but I was hoping to avoid it.

You can directly read 12 bit numbers in Matlab, but my experience has been that it’s very slow. Reading as ordinary bytes and splitting manually was dramatically faster.