Binary representation of numbers...

This is a discussion on Binary representation of numbers... within the C++ Programming forums, part of the General Programming Boards category; Hello everyone. I am trying to write a program in C++ and I need to represent a series of numbers ...

  1. #1
    roc is offline
    Registered User
    Join Date
    May 2003

    Question Binary representation of numbers...

    Hello everyone. I am trying to write a program in C++ and I need to represent a series of numbers in binary form. I need numbers as big as 1,000,000 and I was wondering if C++ has some sort of function to change base 10 numbers into binary numbers?

    Thanks for the help in advance!

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001


    bitset is part of the Standard Template Library. You can use bitset for displaying numbers in binary. For input, you can use strtoul()

    Here's a program I wrote a few months ago that "converts" between bases.

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    I created a program that converts ASCII characters into integers (base 10) and binary (base 2) numbers... it won't help you much, except for maybe the binary function... I was just playing around with recursion on this program...

    	Letter => Number => Binary
    	This Program will take an ASCII character and convert it into a number, then
    	convert it into Binary. The user may enter a single charater, or a string of
    	any length, seeing as the program uses a loop to convert it one charater at a
    	time.  The output is put into a file so it can easily be copied/pasted. The
    	file is overwritten every time the program runs.
    #include <iostream.h>
    #include <fstream.h>
    int power(int),binary(int&,int);
    void main()
    	char cha;
    	int i,ch,cho;
    	ofstream ofile("letnumbin.log",ios::trunc);
    	cout<<"Press Enter after you entered a string or ASCII\n"
    		<<"character to find The Decimal and Binary equivalent:\n\n";
    			cho=ch;	// assigns number to be sent to output file
    				cout<<binary(ch,i);		// destroys int ch to 0 - cant be used ofile
    				ofile<<binary(cho,i);	// uses special assigned number
    int binary(int& ch,int i)
    		return 1;
       	return 0;
    int power(int exponent)
    		return 1;
    Join is in our Unofficial Cprog IRC channel
    Channel: #Tech

    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary representation in C
    By @nthony in forum C Programming
    Replies: 25
    Last Post: 11-10-2007, 12:43 AM
  2. searching and insertion in a binary search tree
    By galmca in forum C Programming
    Replies: 1
    Last Post: 03-26-2005, 05:15 PM
  3. something about binary numbers in c
    By louis_mine in forum C Programming
    Replies: 1
    Last Post: 02-09-2005, 10:22 PM
  4. how to pack 8 x 4 bit binary numbers into a long int?
    By n00bcodezor in forum C Programming
    Replies: 11
    Last Post: 11-19-2001, 05:46 PM
  5. # of ones in Binary representation
    By Matrix01 in forum C Programming
    Replies: 3
    Last Post: 11-07-2001, 10:15 AM

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