Welcome! Log In Create A New Profile

Advanced

Adding data to a buffer variable

Posted by pietvanz 
Adding data to a buffer variable
March 04, 2024 09:50AM
Hi,

I'm working on a routine to write a MIDI file, which involves a lot of bitwise operations to produce a stream of bytes.
I have a working midi read routine, but I was using a string and ASC() function to do the math.

So I thought I would give the buffer variable type a go. (Never used it yet)
The benefit of the buffer would be to be able to directly add bytes and integers to it as raw data.
So when I read that most string operators apply to buffers too, I though that I could add an integer at the end of the buffer like so:
bufVar is Buffer
ar_Var is array of byte
//loop through ar_Var
bufVar+=ar_Var[j]
Unfortunately this results in 3 binary zero's being added at the end too.
Why is that?
When adding a string this way no binary zero's are added.
I have a workaround like so that works:
n=Length(bufVar)+1
bufVar[n]=ar_Var[j]
This code produces neat raw data without the binary zero's.
So problem solved, but it still puzzles me why the simple add method doesn't work...

Kind regards,
Piet
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: