CoolInterview.com - World's Largest Collection of Interview Questions
Start Your Own website Now
Sponsored Links

Interview Questions
Our Services

Get 9,000 Interview Questions & Answers in an eBook.


  • 9500+ Pages
  • 9000 Question & Answers
  • All Tech. Categories
  • 14 MB Content

    Get it now !!



    Send your Resume to 6000 Companies


  • INTERVIEW QUESTIONS HARDWARE HARDWARE AND SOFTWARE DESIGN DETAILS
    Question :
    Write a code to count the no. of 1?s in a binary representation of a number?
    Category Hardware and Software Design Interview Questions
    Rating (1.0) By 167 users
    Added on 7/6/2005
    Views 2568
    Rate it!
    Answers:

    This is the code for any bit compiler...


    #define TESTBIT 1 /*always better to represent like this instead of the code written above....

    or

    place a constant before test bit so that no changes can be made....*/

    int no_of_1s=0;

    for(i=0; i < (sizeof(int) * 8) ; i++)
    {
    if(given_no & (TESTBIT<<i)
    no_of_1s++;

    }



    //for 16-bit no
    //
    int no_of_1s=0;
    int testbit=1;
    for(i=0;i<16;i++)
    {
    if(given_no&testbit)
    no_of_1s++;
    testbit = testbit<<1;
    }
    //now the variable no_of_1s is having the result



    Posted by: subbiah    

    Contact subbiah Contact subbiah

    If you have the better answer, then send it to us. We will display your answer after the approval.
    Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification  Enter the above shown code:*
    Inform me about updated answers to this question

       
    Related Questions
    View Answer
    What is binary search, traversal, hashing?
    View Answer
    What is a kernel,shell?
    View Answer
    Is DOS a real time OS?
    View Answer
    Name some real time OSs.
    View Answer
    What is a real time system?
    View Answer
    Is RISC always fast?
    View Answer
    Difference between RISC and CISC
    View Answer
    How many processors are there in a pentium microprocessor? In Sparc?
    View Answer
    What is a Turing machine?
    View Answer
    What is Finite Automata ?
    View Answer


    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL Hardware and Software Design Interview Questions

    User Options
    Sponsored Links


    Copyright ©2003-2014 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions

    Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Dedicated Servers | C Interview Questions & Answers

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes


    Cache = 1.515137 Seconds