Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 02-19-2004, 03:45 PM   #11
Guru
 
Lord Kalthorn's Avatar
 
Join Date: Dec 2003
Location: Britain
Posts: 13,293
Send a message via MSN to Lord Kalthorn
Default

Lol - I spent all of that time downstairs with sheets of paper trying to work it out! I went thorugh about 10 sheets;

First I tried to work out Decimal to Binary, and then a way to do it

for 5 to Binary (101)

5 / 2 2 rem 1
2 / 2 1 rem 0
1 / 2 0 rem 1

Backwards (this matters on other numbers) this is 101. And that works for all Binary Numbers. The Problem was that this is niether an equation nor anything like any kind of help programming it. I went through Logarithims - but I cannot remmember a thing about them (I'm only 16!) but i'm sure that would be a very good way to do it.

I'm sure thats the way you were trying to do it - but it doesn't help the 'how many times to divide?' question. Logarithims with a quick and easy Logging of the remander would sort this out - but I have no idea how to do it. This may help you!

However; I eventually gave up for today, and I will talk to my Maths teacher whom I am sure will know about Logarithims and then not only I will learn something about them but I can tell you if you haven't already worked it out by then. Decimal to Binary is not the easiest thing to do! even when you're just trying to find an equation let alone put it in code!

I felt bad about syaing that I would try my best to help you - and then not help you - so I went and found information on writing a Unicode to Binary Program:

http://msdn.microsoft.com/library/de...rsiontopic.asp

This is single bit stuff - but it also has up to 64-bit stuff if you want it! It looks easy enough and I hope it can help you.

Hopefully I will be able to help you when I talk to my teacher about it - you don't get a degree in Maths without a great deal of knowledge about Logarithims! I will see what I can learn!

I hope that helped at least a bit - I'm sorry I couldn't find an equation!
__________________

__________________
A Knight is sworn to Honour. His heart knows only Virtue. His blade defends the helpless. His might upholds the Weak. His word speaks only truth. His wrath undoes the Wicked.
Lord Kalthorn is offline   Reply With Quote
Old 02-19-2004, 08:34 PM   #12
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Default Re: I need help with a program I am writing

David - I do have books on it, but its the process of practicing it for myself that is hard.

Lord Kalthorn - WOW!! You have some great info for me to look out. I can't tell you how much this is helping me. I will be researching Logarithims myself to see if I can figure some things out as well. Keep me posted on what you find out. Thanks again, this has been more then enough help!
__________________

ObiWan506 is offline   Reply With Quote
Old 02-20-2004, 01:29 PM   #13
Guru
 
Lord Kalthorn's Avatar
 
Join Date: Dec 2003
Location: Britain
Posts: 13,293
Send a message via MSN to Lord Kalthorn
Default

Lol, its Ok - I'm starting to get a little interested in it too! I'm actually using huge chunks of my Half-Term researching the idea!
__________________
A Knight is sworn to Honour. His heart knows only Virtue. His blade defends the helpless. His might upholds the Weak. His word speaks only truth. His wrath undoes the Wicked.
Lord Kalthorn is offline   Reply With Quote
Old 02-21-2004, 07:45 PM   #14
Baseband Member
 
Join Date: Feb 2004
Posts: 32
Send a message via AIM to Traveller
Default

Here why don't you give this a try:
Code:
#include <stdio.h>
/*------------------------------------------------------------*/
/* Decimal to binary conversion */

void Decimal_2_Binary(unsigned int x, unsigned int c[32])
{
	int bit;		

	for(bit = 0; bit < 32; bit++)
	{
		c[bit] = ((x >> bit) & 1);
	}
}


/*------------------------------------------------------------*/

int main()
{
    int bit;
    unsigned int x;
    unsigned int c[32];		

	
    printf("\nEnter an integer number smaller than 4,294,967,295: ");
    scanf("%u", &x);
    printf("\nConverting decimal to binary:\n");

    Decimal_2_Binary(x, c);

    printf("	Binary == ");

    for(bit = 31; bit >= 0; bit--)
    {
	if(bit == 27 || bit == 23 || bit == 19 || bit == 15 || bit == 11 || bit == 7 || bit == 3)
	{
		printf(" ");
	}


	printf("%u", c[bit]);
    }

	printf("\n\n\n");
	return 0;
}
Traveller is offline   Reply With Quote
Old 02-21-2004, 08:13 PM   #15
Guru
 
Lord Kalthorn's Avatar
 
Join Date: Dec 2003
Location: Britain
Posts: 13,293
Send a message via MSN to Lord Kalthorn
Default

Very interesting! Thanks - I hope he gets it; he will be very happy!

The question is; how do you get 64-bit Binary! Ha! Ha! Ha! Mooooo!! I am a Cow
__________________
A Knight is sworn to Honour. His heart knows only Virtue. His blade defends the helpless. His might upholds the Weak. His word speaks only truth. His wrath undoes the Wicked.
Lord Kalthorn is offline   Reply With Quote
Old 02-22-2004, 04:07 AM   #16
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: I need help with a program I am writing

Thanks traveller. That should work.
__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Old 02-22-2004, 03:28 PM   #17
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Default Re: I need help with a program I am writing

Yes that is very interesting, Traveller. I am copying it now and seeing how it works. I knew that I had to use somekind of loop for the program but I wasn't sure what or how. Thank you very much Traveller for posting this. Anyway so I am going to see how this works and check back with you guys.

P.S. - Lord Kalthorn - That is the next question, how to do the 64 bit binary program. LOL, my question never ends, it just gets bigger,
ObiWan506 is offline   Reply With Quote
Old 02-24-2004, 05:03 AM   #18
Beta Member
 
Join Date: Feb 2004
Posts: 2
Default

that is my way.maybe,it will help u.
#include<stdio.h>
#define MAX 30
#define N 2
main()
{
int a[MAX];
int i,m,n,b;
clrscr();
puts("please enter a number\n");
scanf("%d",&m);
i=0;
do{
b=m%N;
a[i]=b;
m=(m-b)/N;
i++;
}while(m>0);
for(n=i-1;n>=0;n--)
printf("%d",a[n]);
printf("\n");
getch();
}

alone is offline   Reply With Quote
Old 02-24-2004, 05:02 PM   #19
Solid State Member
 
ObiWan506's Avatar
 
Join Date: Feb 2004
Posts: 20
Default Re: I need help with a program I am writing

Thanks alone, unfortunatly I have been busy lately and haven't had a chance to check out Traveller's code or your code. Hopefully I will have some time tonight to check them out. Thanks to everyone for the input I have been recieving.
ObiWan506 is offline   Reply With Quote
Old 02-24-2004, 05:36 PM   #20
Site Team
 
David Lindon's Avatar
 
Join Date: Dec 2002
Posts: 15,233
Default Re: I need help with a program I am writing

Quote:
Originally Posted by ObiWan506
Thanks alone, unfortunatly I have been busy lately and haven't had a chance to check out Traveller's code or your code. Hopefully I will have some time tonight to check them out. Thanks to everyone for the input I have been recieving.
Ok, let us know how you get on!
__________________

__________________
[url=http://www.LNXPS.NET]LNXPS.NET - The XPS Library]
David Lindon is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

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



All times are GMT -5. The time now is 01:45 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0