package en.javarush.task.jdk13.task09.task0938;

/*
Binary encoding
*/

public class Solution {

    public static void main(String[] args) {
        String string = "CodeGym!";
        char[] charArray = string.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            print(charArray[i]);
        }
    }

    private static void print(int number) {
        String result = String.format("In Unicode, the character %s is %d, but in binary it is %s", (char) number, number, toBinary(number));
        System.out.println(result);
    }

    public static String toBinary(int number) {

        int remainder = 0;
        int oneZero = 0;
        int twoZero = 00;
        String binaryRepresentation = "";

        while (number > 0) {
            remainder = number %2; //остаток деления на два
            number = number/2; //делим дальше на два оставшийся номер
            binaryRepresentation = remainder + binaryRepresentation;
        if (binaryRepresentation.length() == 6)
        binaryRepresentation = oneZero + binaryRepresentation;
        else if (binaryRepresentation.length() == 7)
        binaryRepresentation = twoZero + binaryRepresentation;
        }
        return  binaryRepresentation;

}
}