Paul Horechuk ha scritto: > 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. > > I think there is nothing wrong in the code; perhaps something wrong is in gambas. It is common practice to use integers to do this exact kind of things. By definition a byte is unsigned but, even if it was signed, an overflow in addition should lead to one of two things: a silent loss of data (overflow), or an exception/runtime error or whatever. A byte cannot hold values larger than 255, so the value 0x10E is unreasonable - apparently, gambas bytes are not really bytes...
>> 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@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/gambas-user >> > > > > -- Doriano Blengino "Listen twice before you speak. This is why we have two ears, but only one mouth." ------------------------------------------------------------------------------ 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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user