Thread: Decimal to Binary

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Great, it works!

    I dont know where they hide it but thats a cool trick to turn 'int' into 'string' with a '0'.

    Thank you, Anon. You sure know how to recognize different types of trees from quite a long way away.
    Using Windows 10 with Code Blocks and MingW.

  2. #17
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I dont know where they hide it but thats a cool trick to turn 'int' into 'string' with a '0'.
    It's rather well-known, and it turns digits into char's which you can append to a string.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #18
    Registered User
    Join Date
    Dec 2008
    Posts
    104
    You are complicating it too much.
    Use the bitwise & operator, it seems to be indispensable in this program.

    For example, to check if the number passed in parameters has the bit 0 as 1 or 0:
    Code:
    <number_passed_in_params> & (int) pow(2, 0)
    If the remainder of that operation is 0, than it has it as 0, if it is greater than 0, than 1.
    Make a simple loop and through each iteration, apply that.
    Last edited by abraham2119; 04-23-2009 at 09:38 AM.

  4. #19
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Except instead of pow one would use 1 << n for powers of two.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help with decimal to binary Algorithm
    By webznz in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 03:52 AM
  2. Confused by expression.
    By Hulag in forum C Programming
    Replies: 3
    Last Post: 04-07-2005, 07:52 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. binary to decimal
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 03-14-2004, 08:35 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM