Article View: borland.public.jbuilder.java.language
Article #18637Re: Checksum and DatagramPackets...etc
From: Steve Horsley
Date: Tue, 12 May 1998 00:00
Date: Tue, 12 May 1998 00:00
24 lines
1372 bytes
1372 bytes
Try using Integer.parseInt(String s, int radix) where the radix in this case needs to be 16. OTOH, you could decompose the integer into bytes and recompose it using shift-and-mask. I haven't tried the following, but you should get the idea... byte[] sumbytes = new byte[4]; byte[3] = (byte) checksum & 255; byte[2] = (byte) (checksum >> 8) & 255; byte[1] = (byte) (checksum >> 16) & 255; byte[0] = (byte) (checksum >> 24) & 255; rebuild it... int checksumReceived = rxpacket[checksumposition]; checksumReceived <<= 8; checksumReceived += ((int) rxpacket[checksumposition + 2]) & 255; checksumReceived <<= 8; checksumReceived += ((int) rxpacket[checksumposition + 3]) & 255; checksumReceived <<= 8; checksumReceived += ((int) rxpacket[checksumposition + 4]) & 255; Steve
Technical Details
Message-ID:
<3558189D.7E49@anite.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<353FBD5D.B232D72@pitt.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,55f0c2e252bccded X-Google-Attributes: gidf74b3,public From: Steve Horsley <steve_horsley@anite.com> Subject: Re: Checksum and DatagramPackets...etc Date: 1998/05/12 Message-ID: <3558189D.7E49@anite.com> X-Deja-AN: 352492484 Content-Transfer-Encoding: 7bit References: <353FBD5D.B232D72@pitt.edu> Mime-Version: 1.0 Reply-To: steve_horsley@anite.com Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language