convert Binary To Decimal function

convert Binary To Decimal function

Page 1 of 1

1 Replies - 6424 Views - Last Post: 28 April 2010 - 04:16 PM Rate Topic: -----

#1 Vls610  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 53
  • Joined: 29-March 10

convert Binary To Decimal function

Posted 28 April 2010 - 04:05 PM

I actually have two things I need to do.
1. I need to cout my array when the values have been stored, I'm having trouble figuring out how to.
2. I also need the convert Binary To Decimal from the array that I have set up.
The over all objective of this project is converting decimal numbers to binary and binary numbers to decimal numbers.


#include <iostream>
using namespace std;

void binary(int);
void toseeif (int);

int main() 
{
	int number;
    toseeif (number);


system ("pause");
return 0;
}
// Checking to see if the number entered was a positive, or below 0. 
void toseeif (int)
{
     int number;
    cout << "Please enter a positive number: ";
	cin >> number;
	if (number < 0 || number > 250) 
	{
		 cout <<  " You have entered the a number that is out of my range! Please enter again!\n";
		 toseeif (number);
    }
    else {
		cout << number << " converted to binary is: ";
		binary(number);
		cout << endl;
	     }
}
//********************************************************************
// function that converts number to binary 
void binary(int number) 
{
	int remainder;

	if(number <= 1) 
    {
		cout << number;
		return;
	}

	remainder = number%2;
	binary(number >> 1);    
	cout << remainder;
}
//********************************************************************
// Bool!
bool* BitArray(int num)
{ 
     // Set the array 
   bool* number = new bool[8]; 
     // Occupy the array 
   for (int i = 0l; i < 8; i++) 
     { 
          number[i] = (num % 2) == 1;
          num >>= 1;
     }
     // Return the array
     return number;
}
//********************************************************************



Is This A Good Question/Topic? 0
  • +

Replies To: convert Binary To Decimal function

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1086
  • View blog
  • Posts: 4,564
  • Joined: 09-June 09

Re: convert Binary To Decimal function

Posted 28 April 2010 - 04:16 PM

this may be just because ive only been programming for about a year and a half, but this is the first dynamic array of bools i have ever seen
bool* number = new bool[8]; 



i thought id let you know.

But have have you searched the snippet area of DIC, i promise you will find what your looking for
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1