[Gambas-user] Problem with Byte datatype ?

Paul Horechuk horechuk at ...981...
Fri Jan 30 14:53:44 CET 2009


On January 29, 2009, Dominique SIMONART wrote:
> Hi evererybody,
>
> If I code the few lines showed below:
>
> DIM X AS Byte
> DIM Texte AS String[64]
>
>   X = &h2E
>   X += &hE0
>   TextBox1.Text = Hex(X)
>   Texte[X] = Hex(X)
>
> I get '10E' displayed. Is this correct for a byte?
I think the 10E indicates an overflow (the 1 part) and thus an error, as it 
won't fit in the 00 to FF range. The 0E would be the remainder. A question 
would be if you wanted signed or unsigned math. With E0 as signed 
(11100000) this is also -1F (00011111) (ones complement). Adding the 2 
numbers would be 2E - 1F = 0F or something similar.

I think there is actually a twos complement process that should be followed 
instead of the ones complement, but I think you get the picture.

Basically, byte is the wrong datatype for this.

> If you put a breakpoint on the TextBox1 line, the local variables show X
> value as 14 (&h0E) which is correct.
> and the last line ends wit an 'out of bounds' message.
>
> (as a workaround, I actually insert a' X = X MOD 256' instruction just
> before the last line)
>
> If you wonder why the hell I've to use bytes, I'm working on a memory
> capture of an Amiga program ("Captive") running inside the emulator
> WinUAE. In those old days (twenty years ago), memory was 0.0005 Gb and
> byte usage was quite common!
> and more, the memory byte order was not compatible with the actual PC so
> you have to read memory byte by byte to restore the Amiga organisation
>
> regards,
> Dominique Simonart
>
>
> -------------------------------------------------------------------------
>----- This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
Paul Horechuk
      Think Free 
Use Open Source Software




More information about the User mailing list