wood burning stoves 2.0*
The moose likes Java in General and the fly likes ipv6 to numeric format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ipv6 to numeric format" Watch "ipv6 to numeric format" New topic
Author

ipv6 to numeric format

Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147
ipv4 to numeric (this converts 127.0.0.1 to some integer, how to do that for0:0:0:0:0:0:0:1) ?


Searchable nature photo gallery: http://agrozoo.net/jsp/Galery.jsp?l2=en
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
What happened when you tried to give input as 0:0:0:0:0:0:0:1?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Before you write any code, you need to decide what might need changing, so you need a list of differences between IPV4 and IPV6
I'll start you off

IPV6 uses : as a separator instead of .

Joanne
Miran Cvenkel
Ranch Hand

Joined: Nov 23, 2010
Posts: 147
John Jai wrote:What happened when you tried to give input as 0:0:0:0:0:0:0:1?


unforeseen exception, otherwise the problem would not arise at all, obviously.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Okay The existing code works with '.' as a separator and counter is assigned to 3 for ipv4. Do you intend to handle ipv6 too in the same method or in a separate one?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Miran Cvenkel wrote:
John Jai wrote:What happened when you tried to give input as 0:0:0:0:0:0:0:1?


unforeseen exception, otherwise the problem would not arise at all, obviously.


No, it's not obvious at all. There are many different things that could go wrong.

For instance: How many bits in an IPv4 address? How many bits in an IPv6 address? How many bits in an int? How many bits in a long?

Also, you definitely don't want to use math.pow() to shortcut integer multiplication, or bring doubles into it in any way. There are values that long can represent that double can't, so the double version of a long may lose precision--you may not end up with the value you expect.
 
Consider Paul's rocket mass heater.
 
subject: ipv6 to numeric format
 
Similar Threads
How to insert and retreive zip files in to blob column in oracle database?
StringBuffer's setCharAt - near help
I know this sounds crazy
effcient way to parse clob data
String confusion