🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
4 messages
4 total messages Started by Chris Sun, 19 Oct 2003 02:06
ntohs? htons?
#374
Author: Chris
Date: Sun, 19 Oct 2003 02:06
7 lines
1074 bytes
Hi
I have tried looking for these functions Ntohs (Network To Host Short) and
htons(Host to Network Short) functions in Java but can't find any. Is there
a way to implement this function?

Thanks
Chris
Re: ntohs? htons?
#375
Author: John McGrath [TeamB]
Date: Sun, 19 Oct 2003 22:55
19 lines
1461 bytes
On 10/18/2003 at 10:06:55 PM, Chris wrote:

> I have tried looking for these functions Ntohs (Network To Host
> Short) and htons(Host to Network Short) functions in Java but can't
> find any. Is there a way to implement this function?

Can you be more specific about what you are trying to do?

When you write numeric values to streams, the standard Java classes
always use network order, so I doubt that you really need these methods.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Re: ntohs? htons?
#376
Author: Tor Iver Wilhelmsen (TeamB)
Date: Mon, 20 Oct 2003 06:50
9 lines
1258 bytes
"Chris" <cchuah@tycoint.com> writes:

> I have tried looking for these functions Ntohs (Network To Host
> Short) and htons(Host to Network Short) functions in Java but can't
> find any. Is there a way to implement this function?

They are not necessary: The Java language defines byte ordering in a
way to be the same as network byte ordering. So the byte ordering
problems that those functions seek to fix are nonexistent.
Re: ntohs? htons?
#377
Author: Shankar Unni
Date: Mon, 20 Oct 2003 20:19
21 lines
1848 bytes
John McGrath [TeamB] wrote:

> Can you be more specific about what you are trying to do?
> 
> When you write numeric values to streams, the standard Java classes
> always use network order, so I doubt that you really need these methods.

Perhaps he already has a binary stream from somewhere, and wants to
interpret a sequence of 2 bytes as a short.

Answer:

a. write your own routine that can take two bytes and return a short
(and does all the shifting and or'ing), or
b. use java.io.DataInputStream.

  byte[] bytes = .. some binary data ..
  DataInputStream is =
      new DataInputStream(new ByteArrayInputStream(bytes));
  ..
  // call is.read{Short,Long,UnsignedShort,...}()
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