Thread View: aus.computers.java
4 messages
4 total messages
Started by Luke Vanderfluit
Fri, 12 Jan 2001 06:23
Representing bytes in hex
Author: Luke Vanderfluit
Date: Fri, 12 Jan 2001 06:23
Date: Fri, 12 Jan 2001 06:23
15 lines
1577 bytes
1577 bytes
Hi, Who can tell me how to represent my output in hex. 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? L -- Luke Vanderfluit Phone 61 8 8556 6112 Aldinga Beach, South Australia
Re: Representing bytes in hex
Author: Antti S. Brax
Date: Fri, 12 Jan 2001 07:21
Date: Fri, 12 Jan 2001 07:21
16 lines
1795 bytes
1795 bytes
Luke Vanderfluit <luke@chipcity.com.au> wrote in comp.lang.java.programmer: > Who can tell me how to represent my output in hex. Use Integer.toString(int radix) where radix is 16. > I want to read a number of bytes from a file, then replace them with > other bytes. Does this have something to do with your problem of getting a hexadecimal representation of a byte? -- /"\ \ / ASCII RIBBON CAMPAIGN Antti S. Brax - asb@iki.fi X AGAINST HTML MAIL Old school / \ (AND NEWS TOO, dammit) http://www.iki.fi/asb/
Re: Representing bytes in hex
Author: 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/
Re: Representing bytes in hex
Author: Paul Murray
Date: Fri, 12 Jan 2001 21:13
Date: Fri, 12 Jan 2001 21:13
17 lines
1764 bytes
1764 bytes
"Luke Vanderfluit" <luke@chipcity.com.au> wrote in message news:3A5EA2DA.E5EEED27@chipcity.com.au... > Hi, > > Who can tell me how to represent my output in hex. > 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? Integer.toHexString() Remember to zero-fill them. -------------------------------------------------------------- 0x29A - opcode of the beast! http://www.users.bigpond.com/pmurray ICQ: 26066755
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads