Subversion Repositories programming

Rev

Rev 213 | Rev 218 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 213 Rev 215
Line 37... Line 37...
37
    /**
37
    /**
38
     * Method: convert4B()
38
     * Method: convert4B()
39
     * Purpose: Convert a number from it's 4B representation to the
39
     * Purpose: Convert a number from it's 4B representation to the
40
     * corresponding 5B representation.
40
     * corresponding 5B representation.
41
     */
41
     */
42
    public static String convert4B (String _4BNum)
42
    public static byte[] convert4B (byte[] _4BNum)
43
    {
43
    {
-
 
44
        String s = convertToString (_4BNum);
-
 
45
 
44
        int i = encodingTable.length - 1;
46
        int i = encodingTable.length - 1;
45
 
47
 
46
        for (; i >= 0; i--)
48
        for (; i >= 0; i--)
47
            if (encodingTable[i][0].equals(_4BNum))
49
            if (encodingTable[i][0].equals(s))
48
                return encodingTable[i][1];
50
                return convertToByteArray(encodingTable[i][1]);
49
 
51
 
50
        throw new IllegalArgumentException();
52
        throw new IllegalArgumentException();
51
    }
53
    }
52
 
54
 
53
    /**
55
    /**
54
     * Method: convert5B()
56
     * Method: convert5B()
55
     * Purpose: Convert a number from it's 5B representation to the
57
     * Purpose: Convert a number from it's 5B representation to the
56
     * corresponding 4B representation.
58
     * corresponding 4B representation.
57
     */
59
     */
58
    public static String convert5B (String _5BNum)
60
    public static byte[] convert5B (byte[] _5BNum)
59
    {
61
    {
60
        int i = encodingTable.length - 1;
62
        int i = encodingTable.length - 1;
-
 
63
        String s = convertToString (_5BNum);
61
 
64
 
62
        for (; i>=0; i--)
65
        for (; i>=0; i--)
63
            if (encodingTable[i][1].equals(_5BNum))
66
            if (encodingTable[i][1].equals(s))
64
                return encodingTable[i][0];
67
                return convertToByteArray(encodingTable[i][0]);
65
 
68
 
66
        throw new IllegalArgumentException();
69
        throw new IllegalArgumentException();
67
    }
70
    }
-
 
71
 
-
 
72
    public static byte[] convertToByteArray (String num)
-
 
73
    {
-
 
74
        int i;
-
 
75
        byte[] ret = new byte[num.length()];
-
 
76
        byte temp;
-
 
77
 
-
 
78
        for (i=0; i<ret.length; i++)
-
 
79
        {
-
 
80
            if (num.charAt(i) == '0')
-
 
81
                temp = 0;
-
 
82
            else if (num.charAt(i) == '1')
-
 
83
                temp = 1;
-
 
84
            else
-
 
85
                throw new IllegalArgumentException();
-
 
86
            
-
 
87
            ret[i] = temp;
-
 
88
        }
-
 
89
 
-
 
90
        return ret;
-
 
91
    }
-
 
92
 
-
 
93
    public static String convertToString (byte[] num)
-
 
94
    {
-
 
95
        int i;
-
 
96
        String s = new String();
-
 
97
 
-
 
98
        for (i=0; i<num.length; i++)
-
 
99
            s = new String (s + num[i]);
-
 
100
 
-
 
101
        return s;
-
 
102
    }
68
}
103
}
69
 
104