CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #5
    Join Date
    Mar 2009
    Location
    Riga, Latvia
    Posts
    128

    Re: Convert int of unknown number of bits to 32 bits int

    2196550012_10 = 82ECB17C_16

    82_16 = 130
    EC_16 = 236
    B1_16 = 177
    7C_16 = 124

    Seems you have to use masks if you need to split an integer to four octets.

    a.b.c.d

    Code:
    a = (ip >> 24) & 0xFF;
    b = (ip >> 16) & 0xFF;
    c = (ip >>  8) & 0xFF;
    d = (ip      ) & 0xFF;
    And yes some IP-s will be stored as negative integers.

    Tip: read as long, then convert to int:

    Code:
    long a = 2196550012L;
    System.out.println( (int)a );
    Gives the result: -2098417284_10 = 82ECB17C_16.
    Last edited by andrey_zh; July 5th, 2010 at 07:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured