CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Decimal to binary conversion trouble topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-31-2010, 09:51 PM
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bmos31 is on a distinguished road
| More
Decimal to binary conversion trouble

I'm having trouble even getting started with this problem. I've tried looking at other examples, but I'm completely stuck.

The question and my code(not even sure if im on the right track) is as follows:

Write a function called decToBinaryString that recieves a non-negative int and returns a string that is a binary representation of the number input.
tips - concatenate strings together
test odd/even using %
write a main() that test the code

Code:
#include<iostream>

using namespace std;

void intToBinaryString(unsigned long int, char *);

#define ARRAY_SIZE 1000

int main()
{
    unsigned long int number;
    char binary[ARRAY_SIZE];
    int i;

    cout << "Enter a non-negative integer to convert to binary: ";
    cin >> number;
    intToBinaryString(number, binary);
    
    cout << "Binary representation: ";
    for(i = 0; i < binary
    system ("pause");
    return 0;
}

void intToBinaryString(unsigned long int num, char *bin)
{
    int remainder; 
    <strong class="highlight">if</strong>(num%2 == 0)              //even
    {
        do
        {
            remainder = num%2;  
        }while(num > 0);
        
    
    else                        //(nonNeg%2 != 0) odd
                    
}
Reply With Quote
  #2  
Old 08-31-2010, 10:16 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,163
Thanks: 57
Thanked 63 Times in 44 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: Decimal to binary conversion trouble

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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
I have trouble installing external libraries jamort C++ Programming 0 08-31-2010 04:11 AM
Trouble navigating NyARToolkit Suit C# Programming 0 08-31-2010 04:11 AM
Programming File Conversion .PRN eyfifteen C Programming 0 08-28-2010 03:11 AM
Char to Int Conversion ? techinspiration C Programming 4 05-26-2010 08:18 PM
Re: decimal(not really decimal!) to hex conversion Alex C Programming 1 04-18-2009 03:51 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 02:27 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board