• 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
Re: Hex IP to string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hex IP to string


  • Subject: Re: Hex IP to string
  • From: Manuel Darveau <email@hidden>
  • Date: Wed, 20 Mar 2002 18:54:24 -0500

> On Tuesday, March 19, 2002, at 08:56 PM, Manuel Darveau wrote:
>
>> 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?
>
> Make val an unsigned long instead of a long. Otherwise the left shifts
> will propogate the sign bit whenever the sign bit is on. (The high bit.)
> With signed values, 0xff00000000 >> 24 == 0xffffffff instead of
> 0x000000ff.

Hi!
Yeah, you are probably right but strtol return a long... I will try to find
something like strtoul...

Thanks!


Manuel Darveau
-MacKeeper
_______________________________________________
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.

References: 
 >Re: Hex IP to string (From: Greg Titus <email@hidden>)

  • Prev by Date: Re: Copy and Paste in Project Builder?
  • Next by Date: Quicktime for Java And Cocoa
  • Previous by thread: Re: Hex IP to string
  • Next by thread: trapping enter/tab on NSTableView
  • Index(es):
    • Date
    • Thread