Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:21 20 Apr 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Reading binary data from a file

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 410
Posted: 03:00pm 18 Apr 2026
Copy link to clipboard 
Print this post

I am trying to read binary data from a file.

Although using:

open "foo.bmp" for input as #2
hdr$ = input$(#2, hdr$)


Does work, I would really like to read data into an integer array. I tried this:

dim hdr(1000)
load data "foo.bmp", peek(VARADDR, hdr())


but this gives me a syntax error on the 'load data' line.

Any clues?
-Bill
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1447
Posted: 03:04pm 18 Apr 2026
Copy link to clipboard 
Print this post

I think your parameters are incorrect; here, for example, is how to read the width and height of a PNG file

open FN$ + ".png" for input as #1
s$ = INPUT$(24, #1)
'   Read width
w=ASC(MID$(s$,17,1))*16777216
inc w,(ASC(MID$(s$,18,1))*65536)
inc w,(ASC(MID$(s$,19,1))*256)
inc w,ASC(MID$(s$,20,1))
'   Read height
h=ASC(MID$(s$,21,1))*16777216
inc h,(ASC(MID$(s$,22,1))*65536)
inc h,(ASC(MID$(s$,23,1))*256)
inc h,ASC(MID$(s$,24,1))
close #1


so it is INPUT$(number of bytes, #Chanalno.)
'no comment
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 410
Posted: 03:07pm 18 Apr 2026
Copy link to clipboard 
Print this post

Thanks a lot, I had it backwards!
-Bill
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5859
Posted: 05:05pm 18 Apr 2026
Copy link to clipboard 
Print this post

In the newer pico basics, ASC(MID$ can be replaced by the faster BYTE command.

Volhout
PicomiteVGA PETSCII ROBOTS
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 410
Posted: 07:06pm 18 Apr 2026
Copy link to clipboard 
Print this post

Has that change been added to Color Maximite version of MMBasic too, Volhout?

-Bill
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026