Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
About Us Register FAQ Members List Calendar Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old October 10th, 2002   #1 (permalink)
Registered User
 
radiohead2's Avatar
 
Join Date: Apr 2001
Location: MX
Posts: 125
Question C++ question... (easy)

I have a little question, is there a way to represent an integer but using just 0 & 1, i mean in it's binary form?

Like the Java method:

Code:
Integer.toBinaryString(int i)
That method represents an Integer but with it's binary form:

eg:

Code:
int i =8;
stdOut.println(Integer.toBinaryString(int i));
The result on screen is:
Code:
1000
How to make that in C++ ???

thanks
__________________
Dell Inspiron 8000: 1Ghz P!!!, 512 MB SDRAM, GeForce4 Go w/64Mb DDR, UXGA 15" screen 1600x1200, ESS Maestro sound, 40GB HD, DVD-ROM 8x Pete's Plugins. WinXP Pro
radiohead2 is offline   Reply With Quote
Old October 10th, 2002   #2 (permalink)
Banned
 
Ninjaa's Avatar
 
Join Date: Oct 2001
Location: Soviet Canuckistan
Posts: 0
I had to create a function that did that in my first year in Introductory C++. It isn't that hard...

But I don't think that there is a specific function that will do that. (To my knowledge anyway)
Ninjaa is offline   Reply With Quote
Old October 10th, 2002   #3 (permalink)
A BIG BAD BATARD™
 
Xeven's Avatar
 
Join Date: Sep 2001
Posts: 5,517
fast and easy use std..

i.e

Code:
using namespace std;

... blah blah code here ...

int value = 8;
bitset bs(value);
string str = bs.to_string();

cout << str << endl;

.... blah blah code here ...
Note: just dont forget to include bitset

otherwise you can create your own routine like Ninja said, or _itoa when you are using msvc.
__________________

Last edited by Xeven; October 10th, 2002 at 01:58.
Xeven is offline   Reply With Quote
Old October 10th, 2002   #4 (permalink)
Registered User
 
radiohead2's Avatar
 
Join Date: Apr 2001
Location: MX
Posts: 125
Thanks
__________________
Dell Inspiron 8000: 1Ghz P!!!, 512 MB SDRAM, GeForce4 Go w/64Mb DDR, UXGA 15" screen 1600x1200, ESS Maestro sound, 40GB HD, DVD-ROM 8x Pete's Plugins. WinXP Pro
radiohead2 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 18:14.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5