summaryrefslogtreecommitdiffhomepage
path: root/java.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'java.html.markdown')
-rw-r--r--java.html.markdown12
1 files changed, 10 insertions, 2 deletions
diff --git a/java.html.markdown b/java.html.markdown
index 6753b358..4fdd06cc 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -95,6 +95,12 @@ public class LearnJava {
// Byte - 8-bit signed two's complement integer
// (-128 <= byte <= 127)
byte fooByte = 100;
+
+ // If you would like to interpret a byte as an unsigned integer
+ // then this simple operation can help
+ int unsignedIntLessThan256 = 0xff & fooByte;
+ // this contrasts a cast which can be negative.
+ int signedInt = (int) fooByte;
// Short - 16-bit signed two's complement integer
// (-32,768 <= short <= 32,767)
@@ -102,7 +108,7 @@ public class LearnJava {
// Integer - 32-bit signed two's complement integer
// (-2,147,483,648 <= int <= 2,147,483,647)
- int fooInt = 1;
+ int bazInt = 1;
// Long - 64-bit signed two's complement integer
// (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
@@ -110,7 +116,9 @@ public class LearnJava {
// L is used to denote that this variable value is of type Long;
// anything without is treated as integer by default.
- // Note: Java has no unsigned types.
+ // Note: byte, short, int and long are signed. They can have positive and negative values.
+ // There are no unsigned variants.
+ // char, however, is 16-bit unsigned.
// Float - Single-precision 32-bit IEEE 754 Floating Point
// 2^-149 <= float <= (2-2^-23) * 2^127