Ask Question
27 April, 01:48

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. 27 April, 01:59
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers