Skip to main content
deleted 775 characters in body
Source Link
Mak
  • 291
  • 1
  • 7

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

and the textToBinary

private static String textToBinary(String input) {
    StringBuilder binResult = new StringBuilder();
    
    for (byte ch : input.getBytes()) {
        String binary = Integer.toBinaryString(ch);
        switch (binary.length()) {
            case 4:
                binResult.append("0000").append(binary);
                break;
            case 6:
                binResult.append("00").append(binary);
                break;
            case 7:
                binResult.append("0").append(binary);
                break;
            default:
                binResult.append(binary);
        }
    }

    return binResult.toString();
}

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

and the textToBinary

private static String textToBinary(String input) {
    StringBuilder binResult = new StringBuilder();
    
    for (byte ch : input.getBytes()) {
        String binary = Integer.toBinaryString(ch);
        switch (binary.length()) {
            case 4:
                binResult.append("0000").append(binary);
                break;
            case 6:
                binResult.append("00").append(binary);
                break;
            case 7:
                binResult.append("0").append(binary);
                break;
            default:
                binResult.append(binary);
        }
    }

    return binResult.toString();
}

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}
added 772 characters in body
Source Link
Mak
  • 291
  • 1
  • 7

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

and the textToBinary

private static String textToBinary(String input) {
    StringBuilder binResult = new StringBuilder();
    
    for (byte ch : input.getBytes()) {
        String binary = Integer.toBinaryString(ch);
        switch (binary.length()) {
            case 4:
                binResult.append("0000").append(binary);
                break;
            case 6:
                binResult.append("00").append(binary);
                break;
            case 7:
                binResult.append("0").append(binary);
                break;
            default:
                binResult.append(binary);
        }
    }

    return binResult.toString();
}

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

and the textToBinary

private static String textToBinary(String input) {
    StringBuilder binResult = new StringBuilder();
    
    for (byte ch : input.getBytes()) {
        String binary = Integer.toBinaryString(ch);
        switch (binary.length()) {
            case 4:
                binResult.append("0000").append(binary);
                break;
            case 6:
                binResult.append("00").append(binary);
                break;
            case 7:
                binResult.append("0").append(binary);
                break;
            default:
                binResult.append(binary);
        }
    }

    return binResult.toString();
}
deleted 188 characters in body
Source Link
Mak
  • 291
  • 1
  • 7

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

When i test both methods with some demo Binary String with the length of 88000 chars. This is the result i got.

Time taken by old method 531 sec
Time taken by new method 2 sec

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}

When i test both methods with some demo Binary String with the length of 88000 chars. This is the result i got.

Time taken by old method 531 sec
Time taken by new method 2 sec

JavaFX Nodes runs on a separate UI Thread and this Thread should never be used other than to update the UI Components.. Always use a separate Thread to do the operations not related to UI. see this PrimeFinder Example.

And here is my version of your binaryToText

private static String binaryToText(String input) {
    
    if (input.length() % 8 != 0) {
        throw new IllegalArgumentException("input must be a multiple of 8");
    }

    StringBuilder result = new StringBuilder();

    for (int i = 0; i <input.length(); i+=8) {
            int charCode = Integer.parseInt(input.substring(i,i+8), 2);
            result.append((char) charCode);
    }

    return result.toString();
}
added 190 characters in body
Source Link
Mak
  • 291
  • 1
  • 7
Loading
added 4 characters in body
Source Link
Mak
  • 291
  • 1
  • 7
Loading
added 543 characters in body
Source Link
Mak
  • 291
  • 1
  • 7
Loading
Source Link
Mak
  • 291
  • 1
  • 7
Loading