Computing.Net > Forums > Programming > I need help in c plzzz

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

I need help in c plzzz

Reply to Message Icon

Name: Edgar
Date: January 14, 2002 at 15:54:47 Pacific
Comment:

heyyy!!!!.... i need help to make a program to convert decimal numbers (base10) to base 2. i don´t know to start helpp plzzz!!!



Sponsored Link
Ads by Google

Response Number 1
Name: jag mafer
Date: January 14, 2002 at 19:02:36 Pacific
Reply:

well,
first, more clearly define your problem.
do you simply want a prompt that converts a number in to binary out, or do you want a file in to file out? Then i would suggest looking at std::out (at least in c++)
btw, what's this for?
jag mafer


0

Response Number 2
Name: Edgar
Date: January 14, 2002 at 19:16:55 Pacific
Reply:

well i need to convert a decimal number to a binary......... so far i have this code i dunno know if this is ok

#include
#include
#include
int main()
{
int numerator,counter,denomenator=2,cantidad=0;
int remainder=0,start;
char stringvalue[256];
memset(stringvalue,NULL,sizeof(stringvalue));
printf("Introduzca el numero");
scanf("%d",&numerator);
start=numerator;
counter=0;
do{
remainder=numerator%denomenator;
if (remainder==1)
stringvalue[counter]=1;
else
stringvalue[counter]=0;
cantidad=numerator/denomenator;
numerator=cantidad;
counter++;
}while(cantidad!=0);
strrev(stringvalue);
printf("Su numero %d en Binario es: %d",start,stringvalue);
return 0;
}

check it out


0

Response Number 3
Name: nexus
Date: January 15, 2002 at 04:29:04 Pacific
Reply:

THe computer stores teh numbers a binary. printf should have a switch that displays the number in hex.

instead of %d us %x (I think that is the switch)


0

Response Number 4
Name: Bob
Date: January 15, 2002 at 11:24:03 Pacific
Reply:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaHello again! This little program should do the trick.
#include
int main()
{
    int *modulus;
    int interger, bit = 0;
    cout > interger;

    while(interger != 0) {
        *(modulus + bit++) = interger % 2;
        interger = interger / 2;
    }
    bit--;
    while(bit >= 0)
        cout You can use a simple pointer to store you bits in memory and a loop for dividing and obtaining modulus. Keep experimenting and best wishes.



0

Response Number 5
Name:  
Date: January 15, 2002 at 11:31:28 Pacific
Reply:

sorry, to clear that up:

#include"iostream.h"
int main()
{
int *modulus;
int interger, bit = 0;
cout > interger;
while(interger != 0) {
*(modulus + bit++) = interger % 2;
interger = interger / 2;
}
bit--;
while(bit >= 0)
cout << *(modulus + bit--);
return 0;
}


0

Related Posts

See More



Response Number 6
Name:  
Date: January 15, 2002 at 11:46:15 Pacific
Reply:

Ok here goes again. Don't pay attention to the previous two:

#include"iostream.h"
int main()
{
int *modulus;
int interger, bit = 0;
cout > interger;
while(interger != 0) {
*(modulus + bit++) = interger % 2;
interger = interger / 2;
}
bit--;
while(bit >= 0)
cout << *(modulus + bit--);
return 0;
}


0

Response Number 7
Name: bob
Date: January 15, 2002 at 11:48:27 Pacific
Reply:

aaaaaah to hell with this I'll stick to tobacco farming!


0

Response Number 8
Name:  
Date: January 15, 2002 at 12:29:15 Pacific
Reply:


#include
{
int *modulus;
int interger, bit = 0;
cout > interger;
while(interger != 0) {
*(modulus + bit++) = interger % 2;
interger = interger / 2;
}
bit--;
while(bit >= 0)
cout << *(modulus + bit--);
return 0;
}



0

Response Number 9
Name:  
Date: January 15, 2002 at 12:52:40 Pacific
Reply:

This is my last try.#includeint main(){int *modulus;int interger, bit = 0;cout > interger;while(interger != 0) {*(modulus + bit++) = interger % 2;interger = interger / 2;}bit--;while(bit >= 0)cout


0

Response Number 10
Name:  
Date: January 15, 2002 at 13:01:59 Pacific
Reply:

cout > interger;

lines 6 and 7 which never print out.



0

Response Number 11
Name: Mr. A
Date: January 24, 2002 at 05:43:43 Pacific
Reply:

Run this program with the deciaml number as the argument. It converts it to an unsigned long int. It is separated into to nibbles to distinguish the bits easily.

No need for the overhead of C++ here.


#include
#include

int main(int argc, char **argv)
{
int c;
unsigned int val;

if (argc > 1) {
for (c = 0; *(*(argv + 1) + c); c++)
if ((*(*(argv + 1) + c) '9')) {
printf("%s ain't decimal, Honey\n", *(argv + 1));
return (0);
}
printf("%u decimal = ", val=(unsigned int)atol(*(argv + 1)));
for (c = 16; c > 0;) {
printf("%d", (val >> (--c)) & 1);
if (!(c % 4))
printf(" ");
}
printf(" binary\n");
}
return (0);
}

Mr. A


0

Response Number 12
Name: Mr. A
Date: January 24, 2002 at 05:49:45 Pacific
Reply:

This website doesn't take cut & paste literally.

Let's see if it works this time...


#include
#include

int main(int argc, char **argv)
{
int c;
unsigned int val;

if (argc > 1) {
for (c = 0; *(*(argv + 1) + c); c++)
if ((*(*(argv + 1) + c) 57)) {
printf("%s ain't decimal, Honey\n", *(argv + 1));
return (0);
}
printf("%u decimal = ", val=(unsigned int)atol(*(argv + 1)));
for (c = 16; c > 0;) {
printf("%d", (val >> (--c)) & 1);
if (!(c % 4))
printf(" ");
}
printf(" binary\n");
}
return (0);
}


0

Response Number 13
Name: Mr. A
Date: January 24, 2002 at 05:52:53 Pacific
Reply:

If this doesn't work, I'm giving up.
I don't the the html codes for the vertical bars and this just isn't working...


#include
#include

int main(int argc, char **argv)
{
int c;
unsigned int val;

if (argc > 1) {
for (c = 0; *(*(argv + 1) + c); c++)
if ((*(*(argv + 1) + c) 57)) {
printf("%s ain't decimal, Honey\n", *(argv + 1));
return (0);
}
printf("%u decimal = ", val=(unsigned int)atol(*(argv + 1)));
for (c = 16; c > 0;) {
printf("%d", (val >> (--c)) & 1);
if (!(c % 4))
printf(" ");
}
printf(" binary\n");
}
return (0);
}


0

Response Number 14
Name: Venkat Raghavulu A.R
Date: January 27, 2002 at 07:50:09 Pacific
Reply:

Hi,
itoa() does it, the 3rd parameter given 2, converts the number to a "stream" of 1's and 0's. The converted value is in a string format(char[], i mean array of chars.). U can use this is u want to just print the number in 1's and 0's, but if u want to do any arthimatic operations on it, Trust me, use the value as hex and do it. it will work out for sure.
I trust this help us out.

Venkat.


0

Response Number 15
Name: varol
Date: March 13, 2002 at 02:21:01 Pacific
Reply:

char buffer [255];
itoa (iValue,buffer,2);
printf ("binary: %s\n",buffer);



0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: I need help in c plzzz

Need Help immidiatly Please www.computing.net/answers/programming/need-help-immidiatly-please/9603.html

I need help in Java www.computing.net/answers/programming/i-need-help-in-java/7027.html

i need help in using dtpicker in Access www.computing.net/answers/programming/i-need-help-in-using-dtpicker-in-access/1538.html