 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chris Guest
|
Posted: Sun Oct 19, 2003 2:06 am Post subject: ntohs? htons? |
|
|
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
|
|
| Back to top |
|
 |
John McGrath [TeamB] Guest
|
Posted: Sun Oct 19, 2003 10:55 pm Post subject: Re: ntohs? htons? |
|
|
On 10/18/2003 at 10:06:55 PM, Chris wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
Tor Iver Wilhelmsen Guest
|
Posted: Mon Oct 20, 2003 6:50 am Post subject: Re: ntohs? htons? |
|
|
"Chris" <cchuah (AT) tycoint (DOT) com> writes:
| Quote: | 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.
|
|
| Back to top |
|
 |
Shankar Unni Guest
|
Posted: Mon Oct 20, 2003 8:19 pm Post subject: Re: ntohs? htons? |
|
|
John McGrath [TeamB] wrote:
| Quote: | 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,...}()
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|