NNTP-Posting-Date: Thu, 12 May 2011 18:05:19 -0500 Date: Thu, 12 May 2011 16:05:23 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Java puzzler References: <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com> <-8mdnSRPEIdA21HQnZ2dnUVZ_j2dnZ2d@earthlink.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 24 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-wCkofLkZfTdY8U1Gqlg4C0gH4zVPN7lEljaky7o5oRJPSXFv1Fpz3bD/RleHw7BjOoJRqsXxL/TYSRw!ODRUoEqmfAT0nitwOPM9qvGbZifo+x+j8euoewuZwT+InCkkSzY5PiUiO6UlFT2pzpXWLpb6Zpr3!8dNLTcHIGLwlzlrnGP/uT5SSIYq4MH+kcf2s6cN3nhI= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2526 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4026 On 5/12/2011 2:32 PM, markspace wrote: >> On 12/05/2011 4:45 PM, Patricia Shanahan wrote: ... >>> To do that effectively you need a full set of signed and unsigned >>> data types, or, better still, arithmetic types with arbitrary value >>> ranges. > > I'm not sure I understand this bit. Suppose I want a data type to represent the range 0 through 255. As Java is now, with a little care and masking on conversion, I can use byte, despite the fact that it is signed. If I add (byte)100 + (byte)100, I can regard the result as 200, even though Java would print it as -56. If (byte)100 + (byte)100 caused an overflow, I would need an unsigned byte type to do the same job. The overflow trapping becomes much more meaningful if it is based on the actual range the program needs to enforce. For example, if a variable is intended to represent a decimal digit, any value outside 0 through 9 represents an error. If it is supposed to be a month number, the value should be in 1 through 12. Patricia