public class ByteUtil extends Object
| Constructor and Description |
|---|
ByteUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
decodeBcd(byte[] data,
int offset,
int len)
BCD decodes a byte array into a String.
|
static byte[] |
decodeHex(String hexString,
int width)
Deprecated.
Please see class HexUtil
|
static short |
decodeUnsigned(byte signed)
Allow a variable of type
byte to carry lengths or sizes up to 255. |
static byte[] |
encodeBcd(String data,
int num_bytes)
BCD encodes a String into a byte array.
|
static String |
encodeHex(byte value)
Deprecated.
Please see class HexUtil
|
static String |
encodeHex(byte[] bytes)
Deprecated.
Please see class HexUtil
|
static String |
encodeHex(byte[] data,
char delimiter)
Deprecated.
Please see class HexUtil
|
static String |
padLeading(String data,
int width) |
public static byte[] encodeBcd(String data, int num_bytes)
public static String decodeBcd(byte[] data, int offset, int len)
@Deprecated public static byte[] decodeHex(String hexString, int width)
width - The width of the hex encoding (2 or 4)@Deprecated public static String encodeHex(byte value)
@Deprecated public static String encodeHex(byte[] bytes)
@Deprecated public static String encodeHex(byte[] data, char delimiter)
public static short decodeUnsigned(byte signed)
byte to carry lengths or sizes up to 255.
The integral types are signed in Java, so if there is necessary to store
an unsigned type into signed of the same size, the value can be stored
as negative number even if it would be positive in unsigned case.
For example message length can be 0 to 254 and is carried by 1 octet
i.e. unsigned 8 bits. We use a byte variable to read the value from octet stream.
If the length is >127, it is interpreted as negative byte using negative
complement notation.
So length 150 would be interpreted as Java byte -106. If we want to know
the actual value (*length) we need to make a correction to a bigger integral type,
in case of byte it's short. The correction from (negative) byte to short is(short)(256+(short)length)#encodeUnsigned(short)Copyright © 2012-2015 Cloudhopper by Twitter. All Rights Reserved.