u8 a = 0xPA

u8 b = 0xIN
This commit is contained in:
nora 2021-01-31 12:06:33 +01:00
parent b6a130ade3
commit 96543f1455
2 changed files with 45 additions and 2 deletions

View file

@ -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));
}
}*/
}
}

31
src/main/java/u8.java Normal file
View file

@ -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.
* <p>
* 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;
}
}