Skip to content

Instantly share code, notes, and snippets.

@leosabbir
Last active April 27, 2018 23:06
Show Gist options
  • Save leosabbir/568bca61c610996558d6caea33487dd5 to your computer and use it in GitHub Desktop.
Save leosabbir/568bca61c610996558d6caea33487dd5 to your computer and use it in GitHub Desktop.
Conversion of a decimal number into equivalent binary representation
/**
* 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