Post Reply 
71b creating strings with binary data
12-20-2022, 10:07 AM (This post was last modified: 12-20-2022 10:14 AM by dmh.)
Post: #3
RE: 71b creating strings with binary data
I actually did exactly that but didn't show it in the example above. I dimensioned the string, looped and set every character to 0x00 and then set a character in the middle of the string and all the preceding characters get set to space.

I tried it in emu71 and a physical 71b and got the same result.

Null / 0x00 is the problem, any other character (eg 0x01 etc) is fine but 0x00 gets changed to space.

I would have thought it had been done before. How did you do it? Do I need the length of the string set first so the 0x00's are not replaced?

I note that the 41C handles it by requiring a prefix character at the start of the ALPHA register to support null characters.

EDIT: Ok, I think it must be the length, I don't care about the length as I'm using DIM but I'm guessing inserting a character does so I will test again with the length set - thanks!

(12-20-2022 09:50 AM)J-F Garnier Wrote:  Using strings with binary data is usually no problem. I did it a lot of time.
However, the BASIC string type is not an array of bytes, but a string of characters associated with a length.

When you set the value of a character before setting the preceding bytes, these ones are not replaced by spaces, they are, by default, initialized as spaces.
Doing NUM beyond the current length of the string returns 0, not the (default) value of the character that is at this point outside the string.

If you don't set the value of each byte of the string, it means that they are don't care for you, so it shouldn't matter if there are spaces or nulls.
If it really matters for you, then you should initialize the string:
DIM P1$[10]
P1$=RPT$(CHR$(0),10)
or a loop if you don't have a LEX with the RPT$ keyword.

J-F

Calculator Clique on YouTube
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: 71b creating strings with binary data - dmh - 12-20-2022 10:07 AM



User(s) browsing this thread: 3 Guest(s)