Class DigitTools
java.lang.Object
com.github.yellowstonegames.core.DigitTools
Utility class for converting to and from numbers and their String representations; this is mostly wrappers around
Base for compatibility. New code should generally prefer using one of the predefined Base constants in that
class, since you can control whether you want signed or unsigned output using the Base API. This class only produces
unsigned output from its wrapper methods.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends CharSequence & Appendable>
TappendHex(T builder, byte number) static <T extends CharSequence & Appendable>
TappendHex(T builder, char number) static <T extends CharSequence & Appendable>
TappendHex(T builder, double number) static <T extends CharSequence & Appendable>
TappendHex(T builder, float number) static <T extends CharSequence & Appendable>
TappendHex(T builder, int number) static <T extends CharSequence & Appendable>
TappendHex(T builder, long number) static <T extends CharSequence & Appendable>
TappendHex(T builder, short number) static <T extends CharSequence & Appendable>
TappendJoinedFloatsBits(T sb, CharSequence delimiter, float... elements) Joins an array or varargs of floats into an Appendable CharSequence, separated bydelimiter.static Stringbin(byte number) static Stringbin(char number) static Stringbin(double number) static Stringbin(float number) static Stringbin(int number) static Stringbin(long number) static Stringbin(short number) static Stringhex(byte number) static Stringhex(byte[] numbers) static Stringhex(char number) static Stringhex(char[] numbers) static Stringhex(double number) static Stringhex(double[] numbers) static Stringhex(float number) static Stringhex(float[] numbers) static Stringhex(int number) static Stringhex(int[] numbers) static Stringhex(long number) static Stringhex(long[] numbers) static Stringhex(short number) static Stringhex(short[] numbers) static StringhexHash(boolean... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(byte... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(char... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(double... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(float... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(int... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(long... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static StringhexHash(short... array) HashesarrayusingHasherand converts that hash to a hexadecimal String.static intReads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise.static intintFromBin(CharSequence cs, int start, int end) Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise.static intReads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static intintFromDec(CharSequence cs, int start, int end) Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static intintFromHex(char[] cs, int start, int end) Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static intReads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static intintFromHex(CharSequence cs, int start, int end) Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static StringjoinFloatsBits(CharSequence delimiter, float... elements) Joins an array or varargs of floats into a String, separated bydelimiter.static longReads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise.static longlongFromBin(CharSequence cs, int start, int end) Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise.static longReads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent, reading at most 19 characters (20 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static longlongFromDec(CharSequence cs, int start, int end) Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent between the given positionsstartandend, reading at most 19 characters (20 if there is a sign) or until end is reached and returning the result if valid, or 0 if nothing could be read.static longlongFromHex(char[] cs, int start, int end) Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static longReads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static longlongFromHex(CharSequence cs, int start, int end) Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read.static float[]splitFloatFromBits(String source, String delimiter) Given a String containing decimal (seeming nonsense) numbers separated bydelimiter(which is permitted to be present at the end or absent), this parses the numbers into a float array.static int[]splitIntFromDec(String source, String delimiter) Given a String containing decimal numbers separated bydelimiter(which is permitted to be present at the end or absent), this parses the numbers into an int array.static long[]splitLongFromDec(String source, String delimiter) Given a String containing decimal numbers separated bydelimiter(which is permitted to be present at the end or absent), this parses the numbers into a long array.
-
Method Details
-
hex
-
hex
-
hex
-
hex
-
hex
-
hex
-
hex
-
appendHex
-
appendHex
-
appendHex
-
appendHex
-
appendHex
-
appendHex
-
appendHex
-
hex
-
hex
-
hex
-
hex
-
hex
-
hex
-
hex
-
bin
-
bin
-
bin
-
bin
-
bin
-
bin
-
bin
-
longFromHex
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'hex(long)method; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ".
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
This is simply a wrapper aroundBase.readLong(CharSequence, int, int).- Parameters:
cs- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)- Returns:
- the long that cs represents
-
longFromHex
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'hex(long)method; that is, if the first char of a 16-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.
This is simply a wrapper aroundBase.readLong(CharSequence, int, int).- Parameters:
cs- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)start- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 16 characters if end is too large)- Returns:
- the long that cs represents
-
longFromHex
public static long longFromHex(char[] cs, int start, int end) Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the long they represent, reading at most 16 characters (17 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'hex(long)method; that is, if the first digit of a 16-char (or longer) char[] is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFFFFFFFFFF" would return the long -1L when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFFFFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a char array containing only hex digits with an optional sign (no 0x at the start)start- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)- Returns:
- the long that cs represents
-
intFromHex
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'hex(int)method; that is, if the first digit of an 8-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)- Returns:
- the int that cs represents
-
intFromHex
Reads in a CharSequence containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'hex(int)method; that is, if the first digit of an 8-char (or longer) CharSequence is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only hex digits with an optional sign (no 0x at the start)start- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)- Returns:
- the int that cs represents
-
intFromHex
public static int intFromHex(char[] cs, int start, int end) Reads in a char[] containing only hex digits (only 0-9, a-f, and A-F) with an optional sign at the start and returns the int they represent, reading at most 8 characters (9 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can also represent negative numbers as they are printed by such methods as String.format given a %x in the formatting string, or this class'hex(int)method; that is, if the first digit of an 8-char (or longer) char[] is a hex digit 8 or higher, then the whole number represents a negative number, using two's complement and so on. This means "FFFFFFFF" would return the int -1 when passed to this, though you could also simply use "-1 ". If you use both '-' at the start and have the most significant digit as 8 or higher, such as with "-FFFFFFFF", then both indicate a negative number, but the digits will be processed first (producing -1) and then the whole thing will be multiplied by -1 to flip the sign again (returning 1).
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is an odd omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0 if the first char is not a hex digit, or stopping the parse process early if a non-hex-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a char array containing only hex digits with an optional sign (no 0x at the start)start- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 8 or 9 characters if end is too large, depending on sign)- Returns:
- the int that cs represents
-
longFromDec
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent, reading at most 19 characters (20 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. UnlikeintFromDec(CharSequence), this can't effectively be used to read unsigned longs as decimal literals, since anything larger than the highest signed long would be larger than the normal limit for longs as text (it would be 20 characters without a sign, where we limit it to 19 without a sign to match normal behavior).
Should be fairly close to the JDK's Long.parseLong method, but this also supports CharSequence data instead of just String data, and ignores chars after the number. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only digits 0-9 with an optional sign- Returns:
- the long that cs represents
-
longFromDec
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the long they represent between the given positionsstartandend, reading at most 19 characters (20 if there is a sign) or until end is reached and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. UnlikeintFromDec(CharSequence, int, int), this can't effectively be used to read unsigned longs as decimal literals, since anything larger than the highest signed long would be larger than the normal limit for longs as text (it would be 20 characters without a sign, where we limit it to 19 without a sign to match normal behavior).
Should be fairly close to the JDK's Long.parseLong method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only digits 0-9 with an optional signstart- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 19 or 20 characters if end is too large, depending on sign)- Returns:
- the long that cs represents
-
intFromDec
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can technically be used to handle unsigned integers in decimal format, but it isn't the intended purpose. If you do use it for handling unsigned ints, 2147483647 is normally the highest positive int and -2147483648 the lowest negative one, but if you give this a number between 2147483647 and2147483647 + 2147483648, it will interpret it as a negative number that fits in bounds using the normal rules for converting between signed and unsigned numbers.
Should be fairly close to the JDK's Integer.parseInt method, but this also supports CharSequence data instead of just String data, and ignores chars after the number. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before the end of cs is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only digits 0-9 with an optional sign- Returns:
- the int that cs represents
-
intFromDec
Reads in a CharSequence containing only decimal digits (0-9) with an optional sign at the start and returns the int they represent, reading at most 10 characters (11 if there is a sign) and returning the result if valid, or 0 if nothing could be read. The leading sign can be '+' or '-' if present. This can technically be used to handle unsigned integers in decimal format, but it isn't the intended purpose. If you do use it for handling unsigned ints, 2147483647 is normally the highest positive int and -2147483648 the lowest negative one, but if you give this a number between 2147483647 and2147483647 + 2147483648, it will interpret it as a negative number that fits in bounds using the normal rules for converting between signed and unsigned numbers.
Should be fairly close to the JDK's Integer.parseInt method, but this also supports CharSequence data instead of just String data, and allows specifying a start and end. This doesn't throw on invalid input, either, instead returning 0 if the first char is not a decimal digit, or stopping the parse process early if a non-decimal-digit char is read before end is reached. If the parse is stopped early, this behaves as you would expect for a number with less digits, and simply doesn't fill the larger places.- Parameters:
cs- a CharSequence, such as a String, containing only digits 0-9 with an optional signstart- the (inclusive) first character position in cs to readend- the (exclusive) last character position in cs to read (this stops after 10 or 11 characters if end is too large, depending on sign)- Returns:
- the int that cs represents
-
longFromBin
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 64 chars long.
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.- Parameters:
cs- a CharSequence, such as a String, containing only binary digits (nothing at the start)- Returns:
- the long that cs represents
-
longFromBin
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the long they represent, reading at most 64 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 64 chars long.
Should be fairly close to Java 8's Long.parseUnsignedLong method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.- Parameters:
cs- a CharSequence, such as a String, containing only binary digits (nothing at the start)start- the first character position in cs to read fromend- the last character position in cs to read from (this stops after 64 characters if end is too large)- Returns:
- the long that cs represents
-
intFromBin
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 32 chars long.
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.- Parameters:
cs- a CharSequence, such as a String, containing only binary digits (nothing at the start)- Returns:
- the int that cs represents
-
intFromBin
Reads in a CharSequence containing only binary digits (only 0 and 1) and returns the int they represent, reading at most 32 characters and returning the result if valid or 0 otherwise. The first digit is considered the sign bit iff cs is 32 chars long.
Should be fairly close to Java 8's Integer.parseUnsignedInt method, which is a bizarre omission from earlier JDKs. This doesn't throw on invalid input, though, instead returning 0.- Parameters:
cs- a CharSequence, such as a String, containing only binary digits (nothing at the start)start- the first character position in cs to read fromend- the last character position in cs to read from (this stops after 32 characters if end is too large)- Returns:
- the int that cs represents
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty boolean array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty byte array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty short array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty char array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty int array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty long array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty float array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
hexHash
HashesarrayusingHasherand converts that hash to a hexadecimal String.- Parameters:
array- a non-null, non-empty double array- Returns:
- the 16-hex-digit representation of array's hash as a hexadecimal number
-
splitLongFromDec
Given a String containing decimal numbers separated bydelimiter(which is permitted to be present at the end or absent), this parses the numbers into a long array. Thesourceis commonly generated byBase.join(CharSequence, long[]).- Parameters:
source- a String containing decimal numbers separated bydelimiterdelimiter- a non-null, non-empty String that separates numbers in the source- Returns:
- a long array containing the numbers found in
source
-
splitIntFromDec
Given a String containing decimal numbers separated bydelimiter(which is permitted to be present at the end or absent), this parses the numbers into an int array. Thesourceis commonly generated byBase.join(CharSequence, int[]).- Parameters:
source- a String containing decimal numbers separated bydelimiterdelimiter- a non-null, non-empty String that separates numbers in the source- Returns:
- an int array containing the numbers found in
source
-
joinFloatsBits
Joins an array or varargs of floats into a String, separated bydelimiter. This does not write the floats conventionally; instead it converts them to their int bits and reverses the bytes of that int before appending it to the String. This means the float0.0fis written as0, most small powers of 2 are 3 or 4 digits, and the longest numbers have the very least-significant bits set. This is meant to be decoded bysplitFloatFromBits(String, String). The output is not human-readable, and usesBase.SIMPLE64.- Parameters:
delimiter- what separates the encoded float elementselements- an array or varargs of float to encode- Returns:
- a String that holds the encoded floats
-
appendJoinedFloatsBits
public static <T extends CharSequence & Appendable> T appendJoinedFloatsBits(T sb, CharSequence delimiter, float... elements) Joins an array or varargs of floats into an Appendable CharSequence, separated bydelimiter. This does not write the floats conventionally; instead it converts them to their int bits and reverses the bytes of that int before appending it to the Appendable. This means the float0.0fis written as0, most small powers of 2 are 3 or 4 digits, and the longest numbers have the very least-significant bits set. This is meant to be decoded bysplitFloatFromBits(String, String). The output is not human-readable, and usesBase.SIMPLE64.- Type Parameters:
T- must implement both CharSequence and Appendable; commonlyStringBuilderorCharList- Parameters:
sb- any object that implements both CharSequence and Appendable, such asStringBuilderorCharListdelimiter- what separates the encoded float elementselements- an array or varargs of float to encode- Returns:
- sb, potentially after changes
-
splitFloatFromBits
Given a String containing decimal (seeming nonsense) numbers separated bydelimiter(which is permitted to be present at the end or absent), this parses the numbers into a float array. Thesourceis commonly generated byjoinFloatsBits(CharSequence, float...). The output is not human-readable, and usesBase.SIMPLE64.- Parameters:
source- a String containing decimal numbers separated bydelimiterdelimiter- a non-null, non-empty String that separates numbers in the source- Returns:
- a float array containing the numbers found in
source
-