From: "Earl F. Glynn" Subject: D4 Arithmetic Bug or Feature when subtracting byte values? Date: 12 Jul 1998 00:00:00 GMT Message-ID: <6ob23e$dfc@bgtnsc02.worldnet.att.net> Organization: AT&T WorldNet Services X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Newsgroups: borland.public.delphi.objectpascal,alt.comp.lang.borland-delphi,comp.lang.pascal.delphi.misc While converting the ShowImage program in my Computer Lab to Delphi 4, I experienced a problem in converting from (R,G,B) coordinates to (H,S,V) coordinates. I traced the problem to the difference of two components of a TRGBTriple, namely the difference of the two bytes, RGB.rgbtBlue - RGB.rgbtRed. Below is as short example of the problem. I'm guessing the difference of two bytes, when negative, is being treated differently in D4 at least sometimes. (This is deja vu from UCSD to TP conversions for me.) The solution is an extra typecast that wasn't needed before. procedure TForm1.Button1Click(Sender: TObject); VAR a,b : BYTE; Delta: INTEGER; H : INTEGER; begin Delta := 4; a := 40; b := 45; ShowMessage( IntToStr(a - b) ); // -5 OK (or should this be wrong with unsigned Bytes?) H := (a - b) DIV Delta; ShowMessage( IntToSTr(H) ); // 1,073,741,822 was unexpected here H := Integer(a-b) DIV Delta; // Or is Integer(a) - Integer(b) better here? ShowMessage( IntToSTr(H) ); // -1 OK end; Any comments or insight? efg _________________________________________ Earl F. Glynn