@Author Paul Wheaton * /
Public class numbers {
/ ** Swap The Upper and Lower Bytes of A Two Byte Integer.
THIS USEFUL WHEN You NEED TO Convert Between Intel formatted Integers (Little Endian) and Java / Motorola Formatted Integers (BIG Endian).
@Param x The number to be converted.
@Return the conveilted number.
* / public static short endian (short x) {int y = x >> 8; int z = (x% 256) << 8; z | = y; return (short) z;}
/ ** Reverse the byte Order of A Four Byte Integer.
this is useful when you need to convert Between Intel formatted integers (Little Endian) and Java / Motorola Formatted Integers (BIG Endian).
IF The Original Hex Number Was Abcd, The New Hex Number Will Be DCBA.
@Param x The number to be converted.
@ / public static int endian (int x) {int a = x >>> 24; int b = (x >>> 16 ) & 0xff; INT C = (x >>> 8) & 0xff; int D = x & 0xff; x = (D << 24) | (c << 16) | (B << 8) | a; Return x;} / ** Convert a Possibly Negative Valued Byte to A Positive Value Integer.
A Java byte has a value of -128 to 127. With eight bits and no sign, the negative numbers could be represented as a value of 128 to 255. This method makes such a conversion, but stores the result in an integer since Java does Not support unsigned bytes.
@Param B The byte with a possibly negative value.
@return an integer with a value of 0 to 255.
* / public static int referenceopositiveint (byte b) {INT i = B; IF (i <0 ) {I = 256;} return i;}
/ ** Convert An Integer Possibly Negative Valued Byte to a Positive Value Integer.
A Java Byte Has A Value of -128 to 127. with elerative number and no no sign >
This Method Assumes Your Integer Will Be of the Range of 0 To 255. Using a value Outside of this Range Could Generate An Exception.
@Param I The Integer in The Range of 0 To 255.
@Return a byte with a Possibly Negative Value.
* / public static byte PositiveInetTobyte (INT i) {IF (i> 127) {i - = 256;} return (byte) i;} / ** a communication method method to test if an integer is within a particular range.
@Param x The value to test.
@Param min the minimum value for x.
@Param max the maximum value for x.
@return true if (x> = min) and (x <= Max).
* / public static boolean inrange (int x, int min, int max) {return ((x> = min) && (x <= max));}
/ ** a convenience method to test if a double forin a particular ing.
@Param x The value to test.
@Param min the minimum value for x.
@Param max the maximum value for x.
@return true if (x> = min) and (x <= Max).
* / public static boolean inrange (double x, double min, double max) {return ((x> = min) && (x <= max));}
/ ** a convenience method to test if a character is within a particular ranging.
@Param x the character to test.
@Param min the minimum value for x.
@Param max the maximum value for x.
@return true if (x> = min) and (x <= Max).
* / public static boolean inrange (char x, char min, char max) {return ((x> = min) && (x <= max));} private static char [] negs = {' W ',' W ',' S ',' S ',' - '};
/ ** Pass IN A String That Reresents Some Form of Lat or Long and a Decimal Value Is Returned.
* / public static double decimaldegreget (String text) {boolean negative = false; str s = new str (text); S.Replace ("EAST", 'E'); // There Give A False "South" S.Replace ("EAST", 'E'); S.Replace ("EAST", 'E'); for INT i = 0; i
For (int i = 0; i
S.RemoveDoubleSpaces (); s.trim ();
Double Result = 0.0; if (S.Charcount ('')> 0) {// Multiple Numbers Means Some Sort of De De De DEGREES STR chunk = S.Extractword (); Result = str.atod (chunk .tostring ());
// minutes chunk = S.Extractword (); result = (str.atod ()) / 60.0) / 60.0);
// Seconds if (s.Length ()> 0) {chunk = s.extractword (); result = (str.atod ()) / 3600);}} else {// one big number result = Str.atod (S.toString ());
IF (negative) {result = 0 - result;} Return Result;
}