litesoft
Diff Revisions
811
vs
812
for /trunk/Java/core/Anywhere/src/org/litesoft/core/util/Hex.java
|
@@ -53,40 +53,4 @@ |
53 |
53 |
|
} |
54 |
54 |
|
return (char) rv; |
55 |
55 |
|
} |
56 |
|
- |
|
57 |
|
- |
public static String toHex( byte[] pBytes ) |
58 |
|
- |
{ |
59 |
|
- |
if ( pBytes == null ) |
60 |
|
- |
{ |
61 |
|
- |
return null; |
62 |
|
- |
} |
63 |
|
- |
StringBuilder sb = new StringBuilder( pBytes.length + pBytes.length ); |
64 |
|
- |
for ( byte zByte : pBytes ) |
65 |
|
- |
{ |
66 |
|
- |
sb.append( toChar( zByte >>> 4 ) ); |
67 |
|
- |
sb.append( toChar( zByte ) ); |
68 |
|
- |
} |
69 |
|
- |
return sb.toString(); |
70 |
|
- |
} |
71 |
|
- |
|
72 |
|
- |
public static byte[] fromHex( String pString ) |
73 |
|
- |
{ |
74 |
|
- |
if ( pString == null ) |
75 |
|
- |
{ |
76 |
|
- |
return null; |
77 |
|
- |
} |
78 |
|
- |
if ( (pString.length() & 1) == 1 ) |
79 |
|
- |
{ |
80 |
|
- |
throw new IllegalArgumentException( "Can't be HEX as it is 'Odd' Length: '" + pString + "'" ); |
81 |
|
- |
} |
82 |
|
- |
int zCharAt = 0; |
83 |
|
- |
byte[] zBytes = new byte[pString.length() / 2]; |
84 |
|
- |
for ( int i = 0; i < zBytes.length; i++ ) |
85 |
|
- |
{ |
86 |
|
- |
int z1st = fromCharChecked( pString.charAt( zCharAt++ ) ); |
87 |
|
- |
int z2nd = fromCharChecked( pString.charAt( zCharAt++ ) ); |
88 |
|
- |
zBytes[i] = (byte) ((z1st << 4) + z2nd); |
89 |
|
- |
} |
90 |
|
- |
return zBytes; |
91 |
|
- |
} |
92 |
56 |
|
} |