Welcome to Dream.In.Code
Become a Java Expert!

Join 149,940 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,427 people online right now. Registration is fast and FREE... Join Now!




how to store ip with an octet >127

 
Reply to this topicStart new topic

how to store ip with an octet >127

saumya9888
23 Aug, 2008 - 11:01 PM
Post #1

New D.I.C Head
*

Joined: 8 Aug, 2008
Posts: 22


My Contributions
Hi, i was trying to store my machines address which is "10.19.41.177" to a byte array using
CODE
ipadd = InetAddress.getLocalHost().getAddress();


but when i display ipadd[3] it shows "-79" plz tell me how to correct it.BTW:How do we make a byte unsigned the way we do in C++.
User is offlineProfile CardPM
+Quote Post

Gloin
RE: How To Store Ip With An Octet >127
24 Aug, 2008 - 01:59 AM
Post #2

Expert Schmexpert...
Group Icon

Joined: 4 Aug, 2008
Posts: 929



Thanked: 54 times
My Contributions
If nothing else works for you then you can just store/retrieve the value as ((256 + ipadd[3]) % 256) then you'll always get a value between 0..255. Although it seems you shouldn't have to do that every time.
User is online!Profile CardPM
+Quote Post

1lacca
RE: How To Store Ip With An Octet >127
25 Aug, 2008 - 12:37 AM
Post #3

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
[url7http://www.darksleep.com/player/JavaAndUnsignedTypes.html]This should help[/url]
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month