Compiler translation and division remainders

This is a discussion on Compiler translation and division remainders within the C Programming forums, part of the General Programming Boards category; I have two questions. One, the odds of me getting my hands on source code that I actually care about ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    13

    Compiler translation and division remainders

    I have two questions. One, the odds of me getting my hands on source code that I actually care about that was written in Code::Blocks are two small to calculate. Such the case, I cannot open a source file, hit F9, and go. Is there an efficient way of translating other people's source code into your compiler so you can compile it raw?

    Two, I have read the method for converting a number to binary is the number divided by two, the remainder (one or zero) becomes a binary digit, and the result is divided by two. This process continues until the result is zero or < 0. The remainders are then constructed in reverse order to form a set of 0's and 1's that represents the number. I tried to write a program to convert a number into binary, but what I don't know is, how do I take a division, but the remainder in one int array, and the result in an int variable to be re-divided?

    Thanks,
    -CG20

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Modulo 2 will get you the remainder. IE: 5 % 2 would equal 1 then put it in your array something like:
    Code:
    for(i=0; i<32; i++)
    {
        array[i] = num % 2;
        num /=2;
    }

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It's not quite clear from your question: are you using C::B or are they? I'm guessing that since you're saying "F9", you're the one using C::B. In that case, you really should be able to hit F9 and go -- I can, anyway. You'll have to provide more information about what's going wrong.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    13
    I am using C::B. But that's not really important. I may not have all the stuff I need or something.

    mike_g, I don't understand that code. What is that % operator doing? I need to divide a number, and put the remainder in one array, and put the result in another.

    -CG20

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    As mentioned, % gives the remainder. / does division.

Popular pages Recent additions subscribe to a feed

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