Decimal to Binary

This is a discussion on Decimal to Binary within the C++ Programming forums, part of the General Programming Boards category; Great, it works! I dont know where they hide it but thats a cool trick to turn 'int' into 'string' ...

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    794
    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.
    Compiler MSVC++ 2013 with Code::Blocks.

  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).

Page 2 of 2 FirstFirst 12
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, 07:35 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21