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

  • Home
  • SEARCH
  • 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 592467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:44:34+00:00 2026-05-13T15:44:34+00:00

I came across this code for the binary representation of a number. I want

  • 0

I came across this code for the binary representation of a number. I want to know the need for using !! in the code.

int main() {
    int n,i;
    unsigned flag = 1<<(sizeof(int) * 8 - 1);     

    printf("Input the number\n");
    scanf("%d",&n);     
    for(i=0;i<sizeof(int)*8;i++) {    
            printf("%d",!!(n & flag) );    
            n = n << 1;
    }
    return 0;
}
  • 1 1 Answer
  • 1 View
  • 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-13T15:44:34+00:00Added an answer on May 13, 2026 at 3:44 pm

    The flag used has only the MSB set and all other bits cleared, so that when you bitwise and it with number you can test the MSB in the number.

    There are two outcomes of the bitwise anding:

    • Zero – means the number had 0 in its
      MSB.
    • Non-Zero – means the number had 1 in
      its MSB.

    Now we need a way to map

    Non-zero -> 1
    Zero -> 0
    

    so we use the double negation.

    The same thing could have been done using:

    for(i=0;i<sizeof(int)*8;i++) {
    
        (n & flag) ? printf("1"):printf("0");
        n = n << 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this code and need to understand what it is doing. It
I came across this code today AsyncInvoke(OnTimeMessageTimer, (object)null, (ElapsedEventArgs)null); Is there anything wrong with
I just came across this code and a few Google searches turn up no
I came across this snippet of code on MSDN: entityBuilder.Metadata = @res://*/AdventureWorksModel.csdl| res://*/AdventureWorksModel.ssdl| res://*/AdventureWorksModel.msl;
I recently came across this in some code - basically someone trying to create
I came across this line in some code and can't find the syntax defined
Yesterday I read some code of a colleague and came across this: class a_class
I came across a code snippet like this: Timestamp expiryDate = Timestamp.valueOf(dateStr + +
Well I was reading this post and then I came across a code which
I came across this piece of code today: public static byte[] ReadContentFromFile(String filePath) {

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.