BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ntohs? htons?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder JavaAPI
View previous topic :: View next topic  
Author Message
Chris
Guest





PostPosted: Sun Oct 19, 2003 2:06 am    Post subject: ntohs? htons? Reply with quote



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





PostPosted: Sun Oct 19, 2003 10:55 pm    Post subject: Re: ntohs? htons? Reply with quote



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





PostPosted: Mon Oct 20, 2003 6:50 am    Post subject: Re: ntohs? htons? Reply with quote



"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





PostPosted: Mon Oct 20, 2003 8:19 pm    Post subject: Re: ntohs? htons? Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder JavaAPI All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.