FileDocCategorySizeDatePackage
HexTranslator.javaAPI DocAndroid 1.5 API2087Wed May 06 22:41:06 BST 2009org.bouncycastle.util.encoders

HexTranslator

public class HexTranslator extends Object implements Translator
Converters for going from hex to binary and back. Note: this class assumes ASCII processing.

Fields Summary
private static final byte[]
hexTable
Constructors Summary
Methods Summary
public intdecode(byte[] in, int inOff, int length, byte[] out, int outOff)

        int halfLength = length / 2;
        byte left, right;
        for (int i = 0; i < halfLength; i++)
        {
            left  = in[inOff + i * 2];
            right = in[inOff + i * 2 + 1];
            
            if (left < (byte)'a")
            {
                out[outOff] = (byte)((left - '0") << 4);
            }
            else
            {
                out[outOff] = (byte)((left - 'a" + 10) << 4);
            }
            if (right < (byte)'a")
            {
                out[outOff] += (byte)(right - '0");
            }
            else
            {
                out[outOff] += (byte)(right - 'a" + 10);
            }

            outOff++;
        }

        return halfLength;
    
public intencode(byte[] in, int inOff, int length, byte[] out, int outOff)

        for (int i = 0, j = 0; i < length; i++, j += 2)
        {
            out[outOff + j] = hexTable[(in[inOff] >> 4) & 0x0f];
            out[outOff + j + 1] = hexTable[in[inOff] & 0x0f];

            inOff++;
        }

        return length * 2;
    
public intgetDecodedBlockSize()
size of the output block on decoding produced by getEncodedBlockSize() bytes.

        return 1;
    
public intgetEncodedBlockSize()
size of the output block on encoding produced by getDecodedBlockSize() bytes.


                    
      
    
        return 2;