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 1016533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:33:48+00:00 2026-05-16T10:33:48+00:00

I found the following thread: Calculate broadcast address from ip and subnet mask and

  • 0

I found the following thread:
Calculate broadcast address from ip and subnet mask and there the link to http://lpccomp.bc.ca/netmask/netmask.c

Could someone please explain the following line, I don’t understand:

for ( maskbits=32 ; (mask & (1L<<(32-maskbits))) == 0 ; maskbits-- )

especially mask & (1L<<(32-maskbits))

  • 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-05-16T10:33:49+00:00Added an answer on May 16, 2026 at 10:33 am

    << is the bitwise left shift operator; it shifts the bits of a value left by the given amount. Thus 1L<<(32-maskbits) shifts the value 1 to the left 32-maskbits times.

    & is the bitwise AND operator.

    So the loop expression mask & (1L<<(32-maskbits)) == 0 tests all the bits within the value of mask, from lower to higher. The loop will stop on the first (lowest) nonzero bit of mask, at which point maskbits will contain the number of bits above (and including) that bit.

    E.g.

    • if mask == 0xFFFF mask == 0xFFFFFFFF (== binary 11111111111111111111111111111111), the loop will stop on the first iteration, and maskbits will be 32
    • if mask == 0x0001 mask == 0x00000001 (== binary 00000000000000000000000000000001), the loop will again stop on the first iteration, and maskbits will be 32
    • if mask == 0x1000 mask == 0x01000000 (== binary 00000001000000000000000000000000), the loop will stop on the 24th iteration, and maskbits will be 8
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found the following thread very useful http://groups.google.com/group/jqplot-users/browse_thread/thread/1986 ... I would like to get
I found the following which shows how to delete an attribute from XML in
I found the following piece of code from the adw launcher: Object service =
I read every thread I found on StackOverflow on invoking shell commands from Python
I found the following code example (from Telerik ) that I'm trying to understand.
Following code found that output results is not the order, not from small to
I found the following semaphore example. I'm currently learning about thread syncing. I have
Reading through documentation, I found following: 1.9.1 1.8.4 1.8.2 A version of 1.8.2 select
On the MSDN, I have found following: public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string
I found the following lines in a makefile tutorial, but I have some problem

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.