Bits and Bytes

In Java, the byte type is one byte (8 bits) in size.
It can store an integer from -128 to +127.
This page is designed to show you how it does this.
8 7 6 5 4 3 2 1
+/-
sign bit
26=64 25=32 24=16 23=8 22=4 21=2 20=1


Instructions and Questions

  1. Turn on Bit 3 and 1, and press the "Show Value" button. What value is 101?

  2. Turn on Bit 8. Press the "Show Value" button again. What happened?

  3. Turn off Bit 3 so you have 10000001. Can you predict the number before you press the "Show Value" button? What was it? Where you right?

  4. Turn off Bit 1 so you have 10000000. Can you predict the number before you press the "Show Value" button? What was it? Were you right?

  5. What is the largest number possible?

  6. What is the smallest?

  7. Now Turn on Bits 7, 6, and 5 so you have 01110000, which is 112. Press the "Add One" button a few times, until it gets to 120. Can you see the pattern of how the 1's and 0's change? Keep pressing the "Add One" button untill it is 127, and predict the next number if you were to press the "Add one" button one more time.

  8. Were you right? Do you have a better idea on what "overflow" means?

  9. Bit 8 is the sign bit, so 00000001=1 and 10000001 is -1. Is there a difference between "positive zero" (00000000) and "negative zero" (10000000)?

  10. In Java, the byte type is one byte (8 bits) in size. It can store an integer from -128 to 127. The int type is four bytes (32 bits) in size. What is the range of integers it can store?

  11. The ASCII code for the letter "A" is 65, which at first seems like a strange place to begin. Find the binary combination for 65. Does 65 seem to be a more logical choice now?

  12. What do you think the ASCII code for the lower case "a" is? Can you see the logic of this choice?

  13. In Java, the simple data type "int" uses 4 bytes (which is 4 times 8 bits, or 32 bits) What are the smallest and largest integers that you can store in 32 bits of memory?