Displaying an integer in binary format

Hello, I've been wondering how is it possible to display an integer in binary format in VC++ 8 .net 2
With Thanks,
                    Gal Beniamini.


Answer this question

Displaying an integer in binary format

  • ChapiNaples

    In VC6, it can be done by using sprintf("%x", ...). But I don't know whether it works in VC8

  • cRz

    Using sprintf("%x", ...) will create the number in hexadecimal format: not in binary format.



  • Joe Duffy

    Ok, I know of such a way and I will do so. Thanks.
     

  • FHJJr

    Yes: this is possible. It is also one of my favorite interview questions as even though it is not a difficult problem there is the need to balance the data driven portion of the solution against the code driven protion. The 100% code driven and 100% data driven solutions are both possible thought completely unrealistic.

    The best solutions I have seen works at the nibble level - you walk through your data one nibble at a time and then use a table to output the binary representation of each nibble.



  • Displaying an integer in binary format