Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,337 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,110 people online right now. Registration is fast and FREE... Join Now!




coverting to binary

 
Reply to this topicStart new topic

coverting to binary

tootypegs
post 12 Mar, 2008 - 04:24 AM
Post #1


D.I.C Head

**
Joined: 9 Oct, 2007
Posts: 177


My Contributions


is there a was using c++ code to show the binary makeup of a character using c++.

for example displaying the characters 'R' as "01010010"


thanks

This post has been edited by tootypegs: 12 Mar, 2008 - 04:39 AM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 12 Mar, 2008 - 04:39 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,170



Thanked 33 times

Dream Kudos: 25
My Contributions


You can simply take the character, get it's ASCII or HEX value, and convert. Are you familiar with converting other number bases to binary?
User is offlineProfile CardPM

Go to the top of the page

jeronimo0d0a
post 12 Mar, 2008 - 11:32 AM
Post #3


D.I.C Head

**
Joined: 3 Mar, 2008
Posts: 141


My Contributions


Yes it is possible to convert the number into binary. Read the help on _itoa_s or if your compiler doesn't have it itoa.
Hope this helps.

CODE

#include <iostream>
using namespace std;
int main()
{
    int x = 'R';
    char buf[20];
    _itoa_s( x, buf, 19, 2 );
    cout << "The number " << x << " is binary: " << buf;
}

User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 03:26AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month