title: Largest Java Short (32767) plus 1 not turning negative?
body: <p>recently I learned about the two's compliment method of representing both positive and negative integers in the base two system. I then tried to see this in action using java with the following short code:</p>
  <pre><code>int a=2147483647;
  System.out.println(&quot;a: &quot;+a);
  System.out.println(&quot;a+1: &quot;+(a+1));
  short b=32767;
  System.out.println(&quot;b: &quot;+b);
  System.out.println(&quot;b+1: &quot;+(b+1));
  </code></pre>
  <p>Which outputs:</p>
  <blockquote>
  <p>a: 2147483647</p>
  <p>a+1: -2147483648</p>
  <p>b: 32767</p>
  <p>b+1: 32768</p>
  </blockquote>
  <p>Which confuses me because I would think that b+1, being represented in binary as 011111111111111, would turn into 1000000000000000, or in decimal, -32768. What's going on?</p>