8-bit Signed Integer (Java byte)

Java uses 8-bit signed integers for the byte type.
It is represented internally using two’s complement.


Range of 8-bit Signed byte

A byte has 8 bits:

  • 1 bit → sign
  • 7 bits → numeric value

This gives the range:

-128 to +127

Because:

Minimum: 1000 0000 (binary) = -128
Maximum: 0111 1111 (binary) = +127


Binary → Decimal (Signed)

If MSB (most significant bit) = 0

The number is positive.

Example: 0011 0101 → 53

If MSB = 1

The number is negative → use two’s complement:

  1. Invert bits
  2. Add 1
  3. Put minus sign

Example: 1111 0001
Invert → 0000 1110
Add 1 → 0000 1111 = 15
So output = -15


Decimal → 8-bit Signed Binary

Example: Convert -20

  1. Convert +20 → 0001 0100
  2. Invert → 1110 1011
  3. Add 1 → 1110 1100

Final: 1110 1100

Example: Convert +50

50 → 0011 0010


Byte Overflow in Java

Java byte overflows automatically (wrap-around).

Example: byte b = 127;
b++;
Output: -128

Because: 0111 1111 (127)

  • 1
    = 1000 0000 (-128)

Common 8-bit Signed Values

Binary Decimal
1000 0000 -128
1000 0001 -127
1111 1111 -1
0000 0000 0
0000 0001 1
0111 1111 127

Summary

  • byte is an 8-bit signed integer in Java.
  • Range: -128 to +127.
  • Uses two’s complement.
  • MSB = 0 → positive, MSB = 1 → negative.
  • Overflow wraps automatically.

This is essential for understanding low-level operations, bit manipulation, and byte-based IO in Java.


This site uses Just the Docs, a documentation theme for Jekyll.