Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:24:43+00:00 2026-06-08T17:24:43+00:00

String ntohl(int i) { int i1 = i % (256); int i2 = (i

  • 0
String ntohl(int i)
{
    int i1 = i % (256);
    int i2 = (i %(65536))/(256);
    int i3 = (i %(16777216))/(65536);
    int i4 = (i)/(16777216);

    int i5 = i % (2^8);
    int i6 = (i %(2^16))/(2^8);
    int i7 = (i %(2^24))/(2^16);
    int i8 = i/(2^24);

    Log.d(TAG, "i:"+i+"   "+i1+"."+i2+"."+i3+"."+i4);
    Log.d(TAG, "i:"+i+"   "+i5+"."+i6+"."+i7+"."+i8);
    return ""+i1+"."+i2+"."+i3+"."+i4;
}

Hi,

I have a method listed above which returns an ipv4 address. I’ve done the calculation however i5 i6 i7 i8 is not like i1 i2 i3 i4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:24:44+00:00Added an answer on June 8, 2026 at 5:24 pm

    Using modulus can return negative numbers which you might not expect. Try using the following pattern

        int i0 = i & 0xFF;
        int i1 = (i >> 8) & 0xFF;
        int i2 = (i >> 16) & 0xFF;
        int i3 = (i >> 24) & 0xFF;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

String text= 2011-11-19T00:00:00.000-05:00; I have the above String . As the date above is
string abc = 07:00 - 19:00 x = int.Parse(only first two characters) // should
String apkPath = apk.getAbsolutePath(); Log.i(getClass().getName(), addApk(): apkPath = + apkPath); PackageInfo localPackageInfo = pm.getPackageArchiveInfo(apkPath,
I have a problem with a little C script which should run as a
string EV_HOME = System.Environment.GetEnvironmentVariable(EV_HOME); string myFilePath = EV_HOME + \\MyFolder\\MySubFolder; Suppose EV_HOME return C:\myprogram\leanrning\anotherfolder
String str = new String(Hello); Normally I have read, in many articles available on
String object behaves like a Value type when using == and != operators which
string tags = 9,3,12,43,2 List<int> TagIds = tags.Split(','); This doesn't work cause the split
String s = <p>test with only p tag </p>; output should be test with
String[] tokens = s.split(' '); for(int i = 0; i < (tokens.length) - 1;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.