Ask Question
14 December, 04:04

Write a method named decimalToBinary that accepts an integer as a parameter and returns an integer whose digits look like that number's representation in binary (base-2). For example, the call of decimalToBinary (43) should return 101011. Constraints: Do not use a string in your solution. Also do not use any built-in base conversion methods like Integer. toString.

+2
Answers (1)
  1. 14 December, 05:35
    0
    In Java:

    public static int decimalToBinary (int decimal) {

    int binary = 0; / / initial value

    int currUnitPlace = 1; / / working location

    while (decimal > 0) {

    / / put remainder in current unit place

    binary + = currUnitPlace * (decimal%2);

    decimal / = 2; / / move to next bit

    currUnitPlace * = 10; / / move unit place

    }

    return binary;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a method named decimalToBinary that accepts an integer as a parameter and returns an integer whose digits look like that number's ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers