Last active
April 27, 2018 23:06
-
-
Save leosabbir/568bca61c610996558d6caea33487dd5 to your computer and use it in GitHub Desktop.
Conversion of a decimal number into equivalent binary representation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts given Decimal number into Binary representation | |
* @param m decimal number to converto to binary | |
* @return Binary representation of input decimal number | |
*/ | |
public String convert(int m) { | |
String binary = ""; | |
while(m > 0) { | |
binary = (m % 2) + binary; // append new remainder at the beginning | |
m /= 2; | |
} | |
return binary; | |
} // convert |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment