• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ipv6 to numeric format

 
Ranch Hand
Posts: 245
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ipv4 to numeric (this converts 127.0.0.1 to some integer, how to do that for0:0:0:0:0:0:0:1) ?
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened when you tried to give input as 0:0:0:0:0:0:0:1?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Miran Cvenkel
Ranch Hand
Posts: 245
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic