CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - Get Success in Job Interviews Interview Success Kit - 30,000 Interview Que. & Ans.
Covers 30,000+ Interview Questions asked in actual MNC Interviews - all with model answers.

Sponsored Links

Interview Questions
Our Services

INTERVIEW QUESTIONS COMPUTER 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 (3.2) By 10 users
Added on 7/6/2010
Views 1267
Rate it!


Answers:

Source: CoolInterview.com

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++;

}

Source: CoolInterview.com



Source: CoolInterview.com

//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

Source: CoolInterview.com



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 & Answers

    User Options
    India News Network

    Latest 20 Questions
    What is Constructive Dividend in Taxation?
    What is Consolidated tax return in Taxation?
    What is Conduit Approach in Taxation?
    What is Competent Authority (CA) in Taxation?
    What are Compensatory stock options in Taxation?
    What is Compensation in Taxation?
    What is Compensating Adjustment in Taxation?
    What is Comparable Uncontrolled Price (CUP) method in Taxation?
    What is Commodity Tax in Taxation?
    What is Central management and control in Taxation?
    What is Cash Basis (cash method) in Taxation?
    What is Carryover in Taxation?
    What is Captive Bank in Taxation?
    What is Capitalize in Taxation?
    What is Capital Tax in Taxation?
    What is Capital Loss in Taxation?
    What is Capital Gain in Taxation?
    What is Capital Expenditure in Taxation?
    What is Capital Asset in Taxation?
    What is Buy-out Payment in Taxation?



    Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

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

    Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

    MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
    MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

    GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

    IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
    IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

    SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
    SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




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



    Cache = 0.625 Seconds