# Thread: Decimal to binary tutorial?

1. ## Decimal to binary tutorial?

Hello everyone. i am new to this, and i want you all to know from the start that this is a homework so dont help me to mutch :P th thing that i want to know is where can i read about how to make decimal to binary? or at least what kind of things i need to read about to lern this, i dont like cheating but some help in the right way is okey i think.

have a nice day you all. 2. 3. That doesn't help ? 4. Originally Posted by Chrabban That doesn't help ?
If you mean, it doesn't help you, you need to say what && where exactly the problem is. 5. i need a tutorial, so i know what dose what, or what i need to read to understand how to program it myself, sure i can serch for it on Google and copy it but i still dont learn anything from that. 6. If you don't even realize when you're looking at a tutorial, we've got a whole new set of problems. 7. Originally Posted by Chrabban i need a tutorial, so i know what dose what, or what i need to read to understand how to program it myself, sure i can serch for it on Google and copy it but i still dont learn anything from that.
How righteous :P
Searching "How to convert a Decimal number to binary?" is supposed to give results explaining the process, not the source code !
After you know the process exactly and accurately, you can easily write the program.
If you can't, you haven't learn't anything and need to search for "C programming Tutorials" instead. 8. Welcome to the forum, Chrabban! You need to understand the number line. That will work for any number base, 2, 8, 10, 16, whatever. And you need to figure out how you want to work with the number line, to get what you need, because there is more than one way to make it happen.

In a number line, you have each number represented like this:
Code:
```B^8 B^7 B^6 B^5 B^4 B^3 B^2 B^1 B^0
=====================================
1   0   0   1```
Fixed now, thanks to Subsonics.
Where the B is the number base (2 for binary naturally, 10 for decimal), and ^ means "to the power of", in the math sense. (In C, ^ means something non-math, so be clear on that.)

B^0 is just the column for the 1's, up to B-1
B^1 is the 2 (or 10 for decimal) column
B^2 is the 4 (or 100 for decimal) column
B^3 is the column for binary 8 (binary), or 1000's in decimal
etc.

So 1001 equals 8+0+0+1 or 9 in binary, and 1000+0+0+1 or one thousand and one, in decimal. 9. Adak, between 8 and 1 there is also 4 and 2 so 101 binary is 4 + 1 = 5. 1001 is 9, I'm sure you are aware, not trying to school you, just a heads up. Binary Math - Info
Binary Number System - Tutorial 11. Originally Posted by Chrabban Hello everyone. i am new to this, and i want you all to know from the start that this is a homework so dont help me to mutch :P th thing that i want to know is where can i read about how to make decimal to binary? or at least what kind of things i need to read about to lern this, i dont like cheating but some help in the right way is okey i think.

have a nice day you all.
Decimal to binary conversion is actually pretty simple. You need two things...

1) Is the number odd or even?
2) What happens if you divide by 2

Ok... that's your big freebie hint... Now you get to sit down and try to figure out a way to make those two questions into a simple solution to your problem... Work the 4 steps in my .sig and if you get stuck --really stuck, not lazy stuck-- post your code and we'll see what we can do. 12. Originally Posted by Subsonics Adak, between 8 and 1 there is also 4 and 2 so 101 binary is 4 + 1 = 5. 1001 is 9, I'm sure you are aware, not trying to school you, just a heads up.
Thanks, Subsonics. Trying to do too much at the same time. Fixed now. 13. Originally Posted by CommonTater 1) Is the number odd or even?
2) What happens if you divide by 2
Those are actually the same question, if you think about it. 14. Originally Posted by grumpy Those are actually the same question, if you think about it.
Not really... They're two steps in solving the OP's problem... I can do it in a half dozen lines... it'll be interesting to see what he comes up with. 15. Well, since our OP seems to have vanished...(Solution in 20 lines)
Code:
```#include <stdio.h>

int main (void)
{ char binary = {0};
unsigned int number;
int x = 0;

printf("Enter a number from 0 to 4294967295 : ");
scanf("%d", &number);

while(x < 32)
binary[x++] = '0';
do
binary[--x] = (number & 1) + '0';
while ( (number /= 2) > 0 );

printf("32bit binary :  %s\n\n", binary);

return 0; }``` Popular pages Recent additions 