This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why the ip address value is and with int 255

 
Apoorva Dubey
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have a simple program to find my ip address and converting it to String.
I am unable to understand why the `b[i]` value is and with `(int)255` below.

 
Luke Leber
Ranch Hand
Posts: 69
2
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're working with a byte array (whose integral elements range from -128 to 127) IP address octets are generally represented as unsigned values (no negatives).

In order to properly 'unsign' a byte, you can apply a bitwise operation to it that goes hand in hand with the implicit widening of the data-type to 'int'.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic