# convert Binary To Decimal function

Page 1 of 1

## 1 Replies - 10128 Views - Last Post: 28 April 2010 - 04:16 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=170890&amp;s=204225ddaefda85a5f1a4c0b02e99550&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Vls610

Reputation: 1
• 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

• Engineer

Reputation: 1270
• Posts: 4,998
• 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