• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Hex IP to string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hex IP to string


  • Subject: Hex IP to string
  • From: Manuel Darveau <email@hidden>
  • Date: Tue, 19 Mar 2002 23:56:44 -0500

Hi!

I want to convert an IP in the form of "0xffffff00" to 255.255.255.0

I tried:
long val;
val = strtol([@"0xffffff00" cString], nil, 16);
NSLog(@"%@:%ld", subnet, val);
NSLog(@"Subnet:%ld.%ld.%ld.%ld", (val & 0xff000000) >> 24, (val &
0x00ff0000) >> 16, (val & 0x0000ff00) >> 8, (val & 0x000000ff));

This work fine with hex like 0x00ffffff but when you enter 0xff000000 it
seem to have an overflow.

Anybody see what I am missing?


Manuel Darveau
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Hex IP to string
      • From: Greg Titus <email@hidden>
  • Prev by Date: Threading Problem (w/NSConnection)
  • Next by Date: Re: Scripting a Cocoa app
  • Previous by thread: Threading Problem (w/NSConnection)
  • Next by thread: Re: Hex IP to string
  • Index(es):
    • Date
    • Thread