Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo4 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("Въведи число: ");
- int num = sc.nextInt();
- System.out.println(Integer.toBinaryString(num));
- int numOfBit = 0;
- int bitCount = num;
- byte count = 0;
- while (bitCount > 0) {
- bitCount /= 2;
- count++;
- }
- int cons = numOfBit + count;
- while (count > numOfBit) {
- boolean one = (num & (1 << (cons-1))) != 0;
- numOfBit++;
- cons--;
- if (one == true) {
- System.out.print("1");
- }
- if (one == false) {
- System.out.print("0");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement