From 96543f1455ba7868848263828b363d3451259dd2 Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Sun, 31 Jan 2021 12:06:33 +0100 Subject: [PATCH] u8 a = 0xPA u8 b = 0xIN --- src/main/java/TestClass.java | 16 ++++++++++++++-- src/main/java/u8.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/u8.java diff --git a/src/main/java/TestClass.java b/src/main/java/TestClass.java index 897bf9a..2e7ca9f 100644 --- a/src/main/java/TestClass.java +++ b/src/main/java/TestClass.java @@ -1,7 +1,19 @@ public class TestClass { public static void main(String[] args) { - StringOfChars s = new StringOfChars('h', 'a'); + + u8 myByte = new u8((short) 127); + System.out.println(myByte.val()); + + //max array size for u8: 2'050'000'000 - 2'100'000'000 + //max array size for byte: 7'500'000'000 - 10'000'000'000 + //max array size for short: 3'700'000'000 - 4'500'000'000 + + u8[][][] test = new u8[1000][1000][1000]; + System.out.printf("no error for size: %,d", (long) test.length * (long) test[0].length * (long) test[0][0].length); + + + /*StringOfChars s = new StringOfChars('h', 'a'); s.append('l', 'l', 'o'); System.out.println(s.toString()); @@ -19,6 +31,6 @@ public class TestClass { GoodRandom random = new GoodRandom(); for (int i = 0; i < 10; i++) { System.out.println(random.randomInt(20)); - } + }*/ } } \ No newline at end of file diff --git a/src/main/java/u8.java b/src/main/java/u8.java new file mode 100644 index 0000000..9f5acea --- /dev/null +++ b/src/main/java/u8.java @@ -0,0 +1,31 @@ +/** + * An unsigned byte. + * Unlike other programming languages like C, C++ and many others, Java is too high-level to + * bother with having or not having sign bits. It just has them by default. + *

+ * This creates a problem, + * because sometimes you might want to save memory and use unsigned bytes. + * In this case, this class is perfect for you because it does exactly that. + * (The 'exactly that' refers to 'creates a problem') + */ +public class u8 { + + private final byte b; + + /** + * Create a new u8. You need to input a short because that is how Java works. + * The value will be stored in a byte though. + * @param s + */ + public u8(short s) { + b = (byte) s; + } + + /** + * Get the value back. + * @return The value as a short because that is how Java works. + */ + public short val(){ + return b; + } +}