Jump to content
unhuman

How many bytes in a number?

Recommended Posts

Messing around with TI Basic for the Mouse Maze competition...  And, running out of memory.  How many bytes are there used in a number?  Seems bigger than 4 bytes...

  • Like 1

Share this post


Link to post
Share on other sites

Numbers in the stored program are represented as text, leading with token >C8 (unquoted string) and the length of the number (string).

 

10 ALPHA=1492

The number 1492 is represented in memory as

>C8 >04 >31 >34 >39 >32

This, by the way, also includes line numbers in the program (like GOSUB 32760,) which is why I always number my programs by 1 starting at 1.  TIdBiT makes it easy to do this, or you can use the RESEQUENCE command. (NOPE: line numbers are crunched as >C9 "line number" followed by two bytes.  The line number 32767 is represented as >C9 >7F >FF.  This has caused so many things in my life to no longer make sense.)

  • Like 3

Share this post


Link to post
Share on other sites

Now, if you are talking about variables, the length of the variable name is significant and takes up space in both the variable table and the stored program.  Numbers are represented in the value stack in RADIX 100 format, which consumes eight bytes.

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, unhuman said:

Messing around with TI Basic for the Mouse Maze competition...  And, running out of memory.  How many bytes are there used in a number?  Seems bigger than 4 bytes...

All Numbers are 8 bytes in Radix 100 and all Strings are at least 2 bytes, byte 1 is length of string up to 255 and string 1 to 255 bytes.

Program lines are 2 bytes for programs line, 2 bytes for address of line, then 1 byte for length of line and the XB program line.

So for example:

100 ! TEST

would be 12 bytes in total, the extra byte is a >C8 token before the spaceTEST to indicated a string.

  • Like 5

Share this post


Link to post
Share on other sites

Arrays can burn a lot of memory, so take care that the DIM is no larger than necessary.

As a side note, line numbers don't matter, so :

1 REM

2 REM    

3 REM

takes the same memory as :

30001 REM

30002 REM

30003 REM

 

  • Like 2

Share this post


Link to post
Share on other sites
On 7/21/2021 at 4:17 PM, senior_falcon said:

Arrays can burn a lot of memory, so take care that the DIM is no larger than necessary.

 

 

Yes! There are no integers in TI BASIC...

Take care of the Option Base, if you want to store a matrix of 5 colums by 3 lines and that you declare:

DIM MAT(5,3)

You expect to have 5×3 = 15 numbers...  But if you let Option Base 0, indexes start at zero.

So you'll have 6×4 = 24 numbers (9 extra numbers consuming 9×8 = 72 bytes!).

 

Guillaume.

  • Like 4

Share this post


Link to post
Share on other sites
8 hours ago, matthew180 said:

Is there any BASIC dialect on the 99/4A that does *not* use the floating-point for all numbers?

Yes, Cortex BASIC.

 

From the manual: "If a number can be represented in a 16-bit twos complement form, it is stored in integer format."

 

Which is only partially true, as some mathematical operators convert the value to floating point even though the result is an integer. So:

 

A=2     <--- stored as integer

A=A*2 <--- result stored as integer

 

B=2     <--- stored as integer

B=B^2 <--- result stored as floating point

Edited by Stuart
  • Like 4

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...