Note that there are some explanatory texts on larger screens.

plurals
  1. POOnly 7 bits for Java char?
    primarykey
    data
    text
    <p>I'm trying to make a UUencode algorithm and part of my code contains this:</p> <pre><code>for(int x = 0; x &lt; my_chars.length; x++) { if((x+1) % 3 == 0) { char first = my_chars[x-2]; char second = my_chars[x-1]; char third = my_chars[x]; int first_binary = Integer.parseInt(Integer.toBinaryString(first)); int second_binary = Integer.parseInt(Integer.toBinaryString(second)); int third_binary = Integer.parseInt(Integer.toBinaryString(third)); int n = (((first &lt;&lt; 8) | second) &lt;&lt; 8) | third; System.out.print(my_chars[x-2] + "" + my_chars[x-1] + my_chars[x] + Integer.toBinaryString(n)); } } System.out.println(); System.out.println(Integer.toBinaryString('s')); </code></pre> <p>What I'm trying to achieve is to combine those 8 bits from the chars that I get into a big 24 bits int. The problem I'm facing is that the result is a 23 bit int. Say my first 3 chars were:</p> <ul> <li>'T' with a binary representation of <code>01010100</code> </li> <li>'u' with a binary representation of <code>01110101</code> </li> <li>'r' with a binary representation of <code>01110010</code> </li> </ul> <p>The result that I get from my program is a int formed from these bits: <code>10101000111010101110010</code> Which is missing the 0 at the beginning from the representation of 'T'.</p> <p>Also I have included the last 2 lines of code because the binary string that I get from 's' is: <code>1110011</code> which is missing the 0 at the beginning.</p> <p>I have checked if I scrolled by mistake to the right but it does not seem that I have done so. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload