Like Tree2Likes

Decimal to binary tutorial?

This is a discussion on Decimal to binary tutorial? within the C Programming forums, part of the General Programming Boards category; Hello everyone. i am new to this, and i want you all to know from the start that this is ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    3

    Cool 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. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    deadrabbit likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    3
    That doesn't help ?

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by Chrabban View Post
    That doesn't help ?
    If you mean, it doesn't help you, you need to say what && where exactly the problem is.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    3
    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. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you don't even realize when you're looking at a tutorial, we've got a whole new set of problems.

  7. #7
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by Chrabban View Post
    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.
    Last edited by manasij7479; 08-13-2011 at 03:44 PM.
    Adak likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.
    Last edited by Adak; 08-13-2011 at 05:00 PM.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    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.

  10. #10
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    @OP: 2 seconds of google lead me to this:

    Binary Math - Info
    Binary Number System - Tutorial
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Chrabban View Post
    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. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by Subsonics View Post
    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. #13
    Registered User
    Join Date
    Jun 2005
    Posts
    6,202
    Quote Originally Posted by CommonTater View Post
    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.
    Right 98% of the time, and don't care about the other 3%.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by grumpy View Post
    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. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well, since our OP seems to have vanished...(Solution in 20 lines)
    Code:
    #include <stdio.h>
    
    int main (void)
      { char binary[33] = {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; }

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary to Decimal-- Need help
    By Evandb in forum C Programming
    Replies: 5
    Last Post: 05-18-2004, 10:20 AM
  2. binary to decimal ! how?
    By o0o in forum C++ Programming
    Replies: 8
    Last Post: 12-23-2003, 09:31 PM
  3. binary to decimal
    By jk81 in forum C Programming
    Replies: 1
    Last Post: 09-13-2002, 05:20 AM
  4. decimal to binary
    By bugeye in forum C Programming
    Replies: 5
    Last Post: 03-13-2002, 10:50 AM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 10:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21