import java.util.Scanner; public class FloatToBinaryConverter { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { try { // Take user input System.out.print("Enter a floating-point number: "); double userInput = scanner.nextDouble(); // Check if the number is within the valid range if (userInput >= Double.MIN_VALUE && userInput <= Double.MAX_VALUE) { // Convert the number to binary long binaryRepresentation = doubleToBinary(userInput); // Print the binary representation System.out.println("Binary representation: " + binaryRepresentation); // Exit the loop if successful break; } else { // Print an error message and repeat the loop System.out.println("Error: Please enter a valid floating-point number."); } } catch (Exception e) { // Handle input errors (non-numeric input) System.out.println("Error: Invalid input. Please enter a valid floating-point number."); scanner.nextLine(); // Consume the invalid input to avoid an infinite loop } } // Close the scanner scanner.close(); } // Function to convert a double to its binary representation private static long doubleToBinary(double number) { // Extract the raw bits of the double value long bits = Double.doubleToLongBits(number); return Long.toBinaryString(bits); } }public class decToBin{ static void ab(int iput){ String output = ""; if(iput <= 0){ System.out.println("nope"); }else{ int a = iput; for(int i = 0; a > 0; i++){ a = Math.floorDiv(a, 2); output = (a % 2) + output; } } String b = ""; String c = ""; for (int index = 0; index < output.length(); index++) { c = output.charAt(index) + c; } System.out.println(c); } public static void main(String[] args) { System.out.println("test.."); ab(50); } }