Thread: Help

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    1

    Help

    Hello ,
    Can anyone give me some idea how to start assignment. My assignment is write a program that count how many possition of integer by binary presentation. For example
    If I input 7 then it count 1 1 1 ( 3 positions)
    if I input 9 then it count 1001(4 postions)
    Thanks,
    Sara

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685

    I know its old, but it is a good question

    Example
    Code:
    for(int i = 32; i--;) {
        std::cout << (input & (1<<i))?'1':'0';
    }

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I don't know if Sara got it, but I didn't can you explan how does it work, please/
    none...

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Have you tried the FAQ?

    [edit]And please think of a better thread title next time!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed