Created
April 28, 2021 17:39
-
-
Save BT-ICD/f3aa67b9176f3946d5aa5bc3bc7a68c4 to your computer and use it in GitHub Desktop.
Conversion from decimal to binary
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
/** | |
* Example: Conversion from decimal to binary | |
* Reference: https://www.rapidtables.com/convert/number/decimal-to-binary.html | |
* Sample Data: | |
* 11 - 1011 | |
* 12 - 1100 | |
* 13 - 1101 | |
**/ | |
public class DecimalToBinaryDemo { | |
public static void main(String[] args) { | |
int num=13, rem; | |
StringBuilder ans= new StringBuilder(); | |
while(num>0){ | |
rem = num%2; | |
num=num/2; | |
ans.append(rem); | |
} | |
ans.reverse(); | |
System.out.println(ans); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment