aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/Ic2ExpReactorPlanner/TaloniusDecoder.java
blob: 89232eb007e41acbe29e8afb32c3a912fd766571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package Ic2ExpReactorPlanner;

import java.math.BigInteger;

/**
 * Pulls values out of codes from Talonius's old reactor planner.
 * @author Brian McCloud
 */
public class TaloniusDecoder {
    private BigInteger dataStack = null;
    
    public TaloniusDecoder(final String dataCode) {
        dataStack = new BigInteger(dataCode, 36);
    }
    
    public int readInt(final int bits) {
        return readBigInteger(bits).intValue();
    }
    
    private BigInteger readBigInteger(final int bits) {
        BigInteger data = dataStack.and(BigInteger.ONE.shiftLeft(bits).subtract(BigInteger.ONE));
        dataStack = dataStack.shiftRight(bits);
        return data;
    }
}