# \#binaryio

**URL:** https://discourse.julialang.org/tag/binaryio/44.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [How to get the eight bit values of a variable with UInt8?](https://discourse.julialang.org/t/how-to-get-the-eight-bit-values-of-a-variable-with-uint8/128022)

<div class="topic-metadata">

**Author:** [@dk-zen](https://discourse.julialang.org/u/dk-zen)\
**Replies:** 11\
**Last updated:** [April 13, 2025, 8:45pm UTC](https://discourse.julialang.org/t/how-to-get-the-eight-bit-values-of-a-variable-with-uint8/128022 "2025-04-13T20:45:20Z")

</div>

Now I’m reading a binary file. I have got a 8 bits namely “a”. According to the data description, each bit represents a different meaning, I want to read the value represented by 8 bit bits, how can I do it? a = 0x0c # …

---

## [Bits and bytes manipulation library](https://discourse.julialang.org/t/bits-and-bytes-manipulation-library/118843)

<div class="topic-metadata">

**Author:** [@sivakon](https://discourse.julialang.org/u/sivakon)\
**Replies:** 12\
**Last updated:** [September 2, 2024, 1:39pm UTC](https://discourse.julialang.org/t/bits-and-bytes-manipulation-library/118843 "2024-09-02T13:39:33Z")

</div>

Are there any available packages in Julia ecosystem for byte level data manipulation? Similar packages are scodec from Scala - GitHub - scodec/scodec: Scala combinator library for working with binary data Elixir has Bi…

---

## [read!(io,Vector{MyStruct} not equivalent to loop over read with eachindex](https://discourse.julialang.org/t/read-io-vector-mystruct-not-equivalent-to-loop-over-read-with-eachindex/117969)

<div class="topic-metadata">

**Author:** [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Replies:** 4\
**Last updated:** [August 10, 2024, 3:55pm UTC](https://discourse.julialang.org/t/read-io-vector-mystruct-not-equivalent-to-loop-over-read-with-eachindex/117969 "2024-08-10T15:55:33Z")

</div>

I have a packed structure of data in a binary stream that I wish to read in julia. I defined the type struct and then added a read method to dispatch for that type: struct MyStruct A::Int16 B::Int16 C::In…

---

## [Reinterpret byte to Float in julia](https://discourse.julialang.org/t/reinterpret-byte-to-float-in-julia/111670)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 4\
**Last updated:** [March 15, 2024, 4:54pm UTC](https://discourse.julialang.org/t/reinterpret-byte-to-float-in-julia/111670 "2024-03-15T16:54:21Z")

</div>

I have data of UInt8 type and i want to convert it into Float64. typeof(data) = Vector{UInt8} My data looks like :point\_right: data = read(f, N\_points \* 9) = UInt8\[0xdf, 0xfd, 0x5a, 0x80, 0x1c, 0x68, 0x86, 0x3f, 0xb6,…

---

## [File output, binary](https://discourse.julialang.org/t/file-output-binary/110751)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 4\
**Last updated:** [February 27, 2024, 6:38pm UTC](https://discourse.julialang.org/t/file-output-binary/110751 "2024-02-27T18:38:26Z")

</div>

I’m totally new to reading and writing things in files, so even if I use words like stream or stuff like that when coding, I do not truly understand them (and still not completely interested). I found a way to write and…

---

## [Reading binary data from a file](https://discourse.julialang.org/t/reading-binary-data-from-a-file/108695)

<div class="topic-metadata">

**Author:** [@MrBean](https://discourse.julialang.org/u/MrBean)\
**Replies:** 9\
**Last updated:** [January 12, 2024, 12:13pm UTC](https://discourse.julialang.org/t/reading-binary-data-from-a-file/108695 "2024-01-12T12:13:17Z")

</div>

Dear all, This is my first post and I am a baby user of Julia. I would like to read data from a file saved in binary format that comes from the sampler of an analytical instrument. The data is of a complex type and ac…

---

## [Binary reading and matrix allocations: most performant way?](https://discourse.julialang.org/t/binary-reading-and-matrix-allocations-most-performant-way/103929)

<div class="topic-metadata">

**Author:** [@myersm0](https://discourse.julialang.org/u/myersm0)\
**Replies:** 3\
**Last updated:** [October 1, 2023, 8:54pm UTC](https://discourse.julialang.org/t/binary-reading-and-matrix-allocations-most-performant-way/103929 "2023-10-01T20:54:04Z")

</div>

Would anyone be able to offer some insight towards getting faster performance for the below sort of use case? Say I have a struct that holds a Matrix and my primary goal is to fill it with values, possibly transposed, a…

---

## [How do you read structures from a file?](https://discourse.julialang.org/t/how-do-you-read-structures-from-a-file/92646)

<div class="topic-metadata">

**Author:** [@Zweta\_Fuze](https://discourse.julialang.org/u/Zweta_Fuze)\
**Replies:** 18\
**Last updated:** [January 10, 2023, 8:33pm UTC](https://discourse.julialang.org/t/how-do-you-read-structures-from-a-file/92646 "2023-01-10T20:33:11Z")

</div>

Good wishes for the New year. I want to read data that are coming from a device. These data are organized in frames with a fixed structure each one. To give an example I want to read a file “Data.dat” with 100 frames. I…

---

## [Help implementing parallelism with readbytes!](https://discourse.julialang.org/t/help-implementing-parallelism-with-readbytes/92672)

<div class="topic-metadata">

**Author:** [@CodeGodz](https://discourse.julialang.org/u/CodeGodz)\
**Replies:** 9\
**Last updated:** [January 9, 2023, 9:44pm UTC](https://discourse.julialang.org/t/help-implementing-parallelism-with-readbytes/92672 "2023-01-09T21:44:08Z")

</div>

I have to read some TBs of data and I want to read a 10-50GB chunk using readbytes! and process it. Since processing the chunk takes longer than reading it it would be a waste to every time wait for the readbytes!. So I…

---

## [Reading binary file into a Vector of custom struct](https://discourse.julialang.org/t/reading-binary-file-into-a-vector-of-custom-struct/91097)

<div class="topic-metadata">

**Author:** [@bensetterholm](https://discourse.julialang.org/u/bensetterholm)\
**Replies:** 9\
**Last updated:** [December 1, 2022, 5:20pm UTC](https://discourse.julialang.org/t/reading-binary-file-into-a-vector-of-custom-struct/91097 "2022-12-01T17:20:12Z")

</div>

I am trying to find the best way to read a binary file directly into a vector of struct. The binary file has a format so that it could be read in as a vector of objects with format like so (where the file may have any n…

---

## [File IO Buffers too small?](https://discourse.julialang.org/t/file-io-buffers-too-small/89931)

<div class="topic-metadata">

**Author:** [@mwlidar](https://discourse.julialang.org/u/mwlidar)\
**Replies:** 14\
**Last updated:** [November 25, 2022, 5:05pm UTC](https://discourse.julialang.org/t/file-io-buffers-too-small/89931 "2022-11-25T17:05:12Z")

</div>

I typically have the task to read and process large binary data files consisting of relatively small consecutive records (\< 30 kB). If I read each record one after the other the read performance lacks far behind of what …

---

## [Reading binary values from a file](https://discourse.julialang.org/t/reading-binary-values-from-a-file/84936)

<div class="topic-metadata">

**Author:** [@Schneeschaufel](https://discourse.julialang.org/u/Schneeschaufel)\
**Replies:** 3\
**Last updated:** [August 1, 2022, 10:35pm UTC](https://discourse.julialang.org/t/reading-binary-values-from-a-file/84936 "2022-08-01T22:35:09Z")

</div>

I saw the following code (http://www.samuelbosch.com/2014/07/benchmarking-reading-binary-values-from.html) and I was intrigued how close the structure resembles Scheme or Lisp code (I wrote something similar in Bigloo 2…

---

## [Performance of writing binary files](https://discourse.julialang.org/t/performance-of-writing-binary-files/80278)

<div class="topic-metadata">

**Author:** [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Replies:** 2\
**Last updated:** [April 30, 2022, 9:53pm UTC](https://discourse.julialang.org/t/performance-of-writing-binary-files/80278 "2022-04-30T21:53:07Z")

</div>

I am creating a function to write binary data (a data array) to a file. First, I have just reversed the reading function (which reads data almost one byte at a time) and performed a sequential write, but noticed it took…

---

## [Read binary Float128 data](https://discourse.julialang.org/t/read-binary-float128-data/73767)

<div class="topic-metadata">

**Author:** [@Mikel\_Antonana](https://discourse.julialang.org/u/Mikel_Antonana)\
**Replies:** 0\
**Last updated:** [December 29, 2021, 5:06pm UTC](https://discourse.julialang.org/t/read-binary-float128-data/73767 "2021-12-29T17:06:52Z")

</div>

We use our own C function to read Float128 binary data (Readbin code is below) which works correctly with Julia 1.4.2 and earlier versions. With later versions we get the following error: "julia: symbol lookup error…

---

## [Read multiple variables from binary file at once](https://discourse.julialang.org/t/read-multiple-variables-from-binary-file-at-once/69409)

<div class="topic-metadata">

**Author:** [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Replies:** 6\
**Last updated:** [October 8, 2021, 8:51pm UTC](https://discourse.julialang.org/t/read-multiple-variables-from-binary-file-at-once/69409 "2021-10-08T20:51:36Z")

</div>

Hi all, if a binary file contains, e.g. many intergers, how can I elegantly read them at once, Given the total number is known? The most naive way to read them: open(filename) do f a = read(f, Int32) …

---

## [How do I have to read an unknown number of floats in binary data till EOF?](https://discourse.julialang.org/t/how-do-i-have-to-read-an-unknown-number-of-floats-in-binary-data-till-eof/69117)

<div class="topic-metadata">

**Author:** [@Zweta\_Fuze](https://discourse.julialang.org/u/Zweta_Fuze)\
**Replies:** 8\
**Last updated:** [October 3, 2021, 2:53pm UTC](https://discourse.julialang.org/t/how-do-i-have-to-read-an-unknown-number-of-floats-in-binary-data-till-eof/69117 "2021-10-03T14:53:46Z")

</div>

% MATLAB for low-level reading of 32bit-floating point numbers f=fopen(‘Float32.dat’,‘r’); A=fread(f,\[100 inf\],‘single’); % important for me to use inf fclose(f); Julia f=open(“Float32.dat”,“r”); A= read(???); clos…

---

## [Memory usage with mmap file](https://discourse.julialang.org/t/memory-usage-with-mmap-file/59883)

<div class="topic-metadata">

**Author:** [@KKesgin](https://discourse.julialang.org/u/KKesgin)\
**Replies:** 17\
**Last updated:** [September 16, 2021, 3:38am UTC](https://discourse.julialang.org/t/memory-usage-with-mmap-file/59883 "2021-09-16T03:38:55Z")

</div>

Hi All I’m accessing a very large binary file randomly on windows. I don’t dare to put in all the code but I managed to replicate the behavior with a small loop. Could someone please explain to me why this is causing in…

---

## [IO write/read \<strlen\> \<string\>](https://discourse.julialang.org/t/io-write-read-strlen-string/66362)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 15\
**Last updated:** [August 17, 2021, 8:24pm UTC](https://discourse.julialang.org/t/io-write-read-strlen-string/66362 "2021-08-17T20:24:27Z")

</div>

With the suggestions below: # write number as type T function writenum(io, num, T) write(io, T(num)) end # read n numbers of type T function readnum(io, T, n) s = sizeof(T) f = zeros(UInt8, s\*n) readbyte…

---

## [Read a single element vs array from stream](https://discourse.julialang.org/t/read-a-single-element-vs-array-from-stream/66328)

<div class="topic-metadata">

**Author:** [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Replies:** 3\
**Last updated:** [August 13, 2021, 9:37pm UTC](https://discourse.julialang.org/t/read-a-single-element-vs-array-from-stream/66328 "2021-08-13T21:37:27Z")

</div>

Since the single case is used often, I use read1T as a convenience function. Novice question: can the two functions be combined without violating type stability? Or, more generally, does Union{T, AbstractArray{T}} as i…

---

## [Binary-read fixed-length String](https://discourse.julialang.org/t/binary-read-fixed-length-string/66080)

<div class="topic-metadata">

**Author:** [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Replies:** 8\
**Last updated:** [August 12, 2021, 8:34am UTC](https://discourse.julialang.org/t/binary-read-fixed-length-string/66080 "2021-08-12T08:34:03Z")

</div>

I was wondering how to read a fixed-length character string from a binary file. My file is formatted like this: Int32|4-byte string|array of Float32's . . . The string consists of just four plain ASCII characters wit…

---

## [DRY reading binary structured data](https://discourse.julialang.org/t/dry-reading-binary-structured-data/65420)

<div class="topic-metadata">

**Author:** [@hacklint](https://discourse.julialang.org/u/hacklint)\
**Replies:** 8\
**Last updated:** [July 30, 2021, 11:08pm UTC](https://discourse.julialang.org/t/dry-reading-binary-structured-data/65420 "2021-07-30T23:08:10Z")

</div>

Hi, I’m trying to create a Julia reader for a binary block-based file format and run into different issues depending on which approach I try. There are many different types of blocks, but essentially they look something…

---

## [Selectively unpacking binary data](https://discourse.julialang.org/t/selectively-unpacking-binary-data/64768)

<div class="topic-metadata">

**Author:** [@Mikhail\_Kagalenko](https://discourse.julialang.org/u/Mikhail_Kagalenko)\
**Replies:** 1\
**Last updated:** [July 25, 2021, 11:08am UTC](https://discourse.julialang.org/t/selectively-unpacking-binary-data/64768 "2021-07-25T11:08:57Z")

</div>

I need to unpack a few values of known types and offsets from a binary file. The difference with earlier discussed cases is, firstly, that the values are not adjacent in the file, so it is necessary to specify offsefs; …

---

## [Reading/Writing struct instance to file as binary](https://discourse.julialang.org/t/reading-writing-struct-instance-to-file-as-binary/63818)

<div class="topic-metadata">

**Author:** [@nullmap](https://discourse.julialang.org/u/nullmap)\
**Replies:** 7\
**Last updated:** [July 2, 2021, 11:02am UTC](https://discourse.julialang.org/t/reading-writing-struct-instance-to-file-as-binary/63818 "2021-07-02T11:02:15Z")

</div>

Hi everyone, I am looking into possible solutions for persisting struct instances on disk as binary data. I’m using credentials data as an MVP example. The following code works as I expect. I create a struct with some f…

---

## [Writing larger than expected binary files](https://discourse.julialang.org/t/writing-larger-than-expected-binary-files/62600)

<div class="topic-metadata">

**Author:** [@k945](https://discourse.julialang.org/u/k945)\
**Replies:** 1\
**Last updated:** [June 12, 2021, 3:23am UTC](https://discourse.julialang.org/t/writing-larger-than-expected-binary-files/62600 "2021-06-12T03:23:59Z")

</div>

When using FortranFiles, I was wondering why writing a new file, with the same data and structure as the original, produces a file whose size is significantly larger (~925MB) than the original (~25MB). Is there a compres…

---

## [Reading 12 bit integers from file](https://discourse.julialang.org/t/reading-12-bit-integers-from-file/60173)

<div class="topic-metadata">

**Author:** [@Shawly](https://discourse.julialang.org/u/Shawly)\
**Replies:** 4\
**Last updated:** [April 28, 2021, 3:42pm UTC](https://discourse.julialang.org/t/reading-12-bit-integers-from-file/60173 "2021-04-28T15:42:20Z")

</div>

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 K…

---

## [Reading byte-aligned struct from binary file](https://discourse.julialang.org/t/reading-byte-aligned-struct-from-binary-file/59323)

<div class="topic-metadata">

**Author:** [@GeraldJansen](https://discourse.julialang.org/u/GeraldJansen)\
**Replies:** 2\
**Last updated:** [April 15, 2021, 1:08pm UTC](https://discourse.julialang.org/t/reading-byte-aligned-struct-from-binary-file/59323 "2021-04-15T13:08:05Z")

</div>

I need to read data from a binary file created by a C program using a byte-aligned struct. Below is a reduced version of the C program and my best effort at reading the binary file in Julia. #include \<stdio.h\> typedef …

---

## [Open EEG binary file](https://discourse.julialang.org/t/open-eeg-binary-file/55972)

<div class="topic-metadata">

**Author:** [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Replies:** 12\
**Last updated:** [February 25, 2021, 6:58pm UTC](https://discourse.julialang.org/t/open-eeg-binary-file/55972 "2021-02-25T18:58:00Z")

</div>

Hi, I am trying to open an EEG BrainVision binary file, but I have a problem… Please help :frowning: To open the binary, I am using the solution provided in this discussion by @stevengj (thank you). The data is said t…

---

## [Converting an Array of Byte to Array{T}](https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676)

<div class="topic-metadata">

**Author:** [@Clonkk](https://discourse.julialang.org/u/Clonkk)\
**Replies:** 2\
**Last updated:** [January 20, 2021, 4:25pm UTC](https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676 "2021-01-20T16:25:31Z")

</div>

Hello, I have binary data read from SQLite database in the form of Array{Uint8}. What would be the best solution to convert this binary data into an Array{T} (convert function perform element wise conversion and thus d…

---

## [Fast reading of multiple big-endian binary files](https://discourse.julialang.org/t/fast-reading-of-multiple-big-endian-binary-files/52060)

<div class="topic-metadata">

**Author:** [@Thomas\_Lei](https://discourse.julialang.org/u/Thomas_Lei)\
**Replies:** 1\
**Last updated:** [December 18, 2020, 5:13pm UTC](https://discourse.julialang.org/t/fast-reading-of-multiple-big-endian-binary-files/52060 "2020-12-18T17:13:47Z")

</div>

Hi all, I have to read and preprocess a huge quantity of binary (big-endian) data from thousands of files. I managed to get everything to work properly, but my function is slow… However, as I’m a Julia beginner, I doubt…

---

## [Unpacking binary data into a Julia struct](https://discourse.julialang.org/t/unpacking-binary-data-into-a-julia-struct/32941)

<div class="topic-metadata">

**Author:** [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Replies:** 7\
**Last updated:** [November 25, 2020, 8:43am UTC](https://discourse.julialang.org/t/unpacking-binary-data-into-a-julia-struct/32941 "2020-11-25T08:43:17Z")

</div>

I’m having a hard time finding an example in Julia v1.0+ for handling unpacking binary data into a Julia struct. Is there an easy way to do this? Say I have some custom struct Test and wanted to read some binary data fr…

[Next page](https://discourse.julialang.org/tag/binaryio/44.md?match_all_tags=true&page=1&tags%5B%5D=binaryio)
