Skip to content

Instantly share code, notes, and snippets.

@iamgauravbisht
Created December 28, 2023 23:08
Show Gist options
  • Save iamgauravbisht/6e8612a392eae3036a59eaf033d03312 to your computer and use it in GitHub Desktop.
Save iamgauravbisht/6e8612a392eae3036a59eaf033d03312 to your computer and use it in GitHub Desktop.
Decimal To Binary
package BinaryAndDecimal;
import java.util.Scanner;
// Decimal to Binary Conversion
public class DecimalToBinary {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.print("Enter a number : ");
int decimal = s.nextInt();
String result ="";
while(decimal>0){
int rem = decimal%2;
decimal = decimal/2;
result= rem + result;
}
System.out.println("Binary :" + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment