Article View: aus.computers.java
Article #299Re: Representing bytes in hex
From: Jeff Robertson
Date: Fri, 12 Jan 2001 14:27
Date: Fri, 12 Jan 2001 14:27
29 lines
2066 bytes
2066 bytes
In article <3A5EA2DA.E5EEED27@chipcity.com.au>,
Luke Vanderfluit <luke@chipcity.com.au> wrote:
> Hi,
>
> Who can tell me how to represent my output in hex.
Either use Integer.toHexString(), as suggested, or do something like
the following:
System.out.print( Character.forDigit( b >> 4 & 0xf, 16) );
System.out.println( Character.forDigit( b & 0xf, 16) );
The main advantage of doing it this way is that the above always prints
exactly 2 digits, whereas toHexString() will vary.
> I want to read a number of bytes from a file, then replace them with
> other bytes.
> I can read the bytes OK, but how to represent them in hex?
As someone else pointed out, these are two separate issues. Please
explain further.
--
"I'm a snotty E-commerce server software coder." - Joona Palaste, c.l.c.
http://www.geocities.com/jeff_robertson
Sent via Deja.com
http://www.deja.com/
Technical Details
Message-ID:
<93n48j$caf$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!216.218.236.179.MISMATCH!news!news.he.net!news-hog.berkeley.edu!ucberkeley!news.maxwell.syr.edu!newspeer.monmouth.com!nntp2.deja.com!nnrp1.deja.com!not-for-mailReferences:
<3A5EA2DA.E5EEED27@chipcity.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10a146,e0719ed8420f42f6 X-Google-Attributes: gid10a146,public X-Google-Thread: 113ae9,e0719ed8420f42f6 X-Google-Attributes: gid113ae9,public X-Google-Thread: 10d6db,e0719ed8420f42f6 X-Google-Attributes: gid10d6db,public X-Google-ArrivalTime: 2001-01-12 06:43:13 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!216.218.236.179.MISMATCH!news!news.he.net!news-hog.berkeley.edu!ucberkeley!news.maxwell.syr.edu!newspeer.monmouth.com!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: Jeff Robertson <jeff_robertson@yahoo.com> Newsgroups: aus.computers.java,comp.lang.java.help,comp.lang.java.programmer Subject: Re: Representing bytes in hex Date: Fri, 12 Jan 2001 14:27:42 GMT Organization: Deja.com Lines: 29 Message-ID: <93n48j$caf$1@nnrp1.deja.com> References: <3A5EA2DA.E5EEED27@chipcity.com.au> NNTP-Posting-Host: 209.246.161.130 X-Article-Creation-Date: Fri Jan 12 14:27:42 2001 GMT X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) X-Http-Proxy: 1.0 x68.deja.com:80 (Squid/1.1.22) for client 209.246.161.130 X-MyDeja-Info: XMYDJUIDjeff_robertson