Ascii to binary

Hey guys, I am trying to do a simple program where I ask the user how many bits they want to be represented, then ask what ASCII character they want to convert to binary and output the binary. For instance, if a user wants to use 7 bits and use the ascii 7, it should display 0110111. If they wanted 8 bits it would be 00110111 and if they wanted 9 bits it would be 000110111 etc etc.
Right now I am using bitset to convert from ASCII to binary, but I see I can only do this by declaring how many bits I want rather then take what the user inputs by using
bitset<Number of bits here> binary(user's ASCII);
See my reply to another thread:

http://www.cplusplus.com/forum/general/81758/#msg439040


HTH
I hate people deleting their posts after getting their answer. AtomicX does that so I'll quote him here:

AtomicX wrote:
Hey guys, I am trying to do a simple program where I ask the user how many bits they want to be represented, then ask what ASCII character they want to convert to binary and output the binary. For instance, if a user wants to use 7 bits and use the ascii 7, it should display 0110111. If they wanted 8 bits it would be 00110111 and if they wanted 9 bits it would be 000110111 etc etc.
Right now I am using bitset to convert from ASCII to binary, but I see I can only do this by declaring how many bits I want rather then take what the user inputs by using
bitset<Number of bits here> binary(user's ASCII);
closed account (o1vk4iN6)
Why is it even possible to delete the opening post ? I guess some people think it'll delete the thread ?
Topic archived. No new replies allowed.