FC18: Replace reminder with mask on the NCR1632 fraction encoder
This commit is contained in:
parent
c6144b8956
commit
c86e90fee7
4 changed files with 86 additions and 32 deletions
|
|
@ -118,40 +118,46 @@ final public class FourCornerRecipe {
|
|||
}
|
||||
|
||||
static public List<Integer> embedNCR1632Denominator(BigInteger value) {
|
||||
return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XD.getStart());
|
||||
return embedNCR1632Value(new ArrayList<>(), value, FourCornerDotCake.FC_NCR1632_XD.getStart());
|
||||
}
|
||||
|
||||
static public List<Integer> embedNCR1632Numerator(BigInteger value) {
|
||||
return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XN.getStart());
|
||||
return embedNCR1632Value(new ArrayList<>(), value, FourCornerDotCake.FC_NCR1632_XN.getStart());
|
||||
}
|
||||
|
||||
static private List<Integer> embedNCR1632Value(BigInteger value, int bankStart) {
|
||||
static public void embedNCR1632Denominator(List<Integer> result, BigInteger value) {
|
||||
embedNCR1632Value(result, value, FourCornerDotCake.FC_NCR1632_XD.getStart());
|
||||
}
|
||||
|
||||
static public void embedNCR1632Numerator(List<Integer> result, BigInteger value) {
|
||||
embedNCR1632Value(result, value, FourCornerDotCake.FC_NCR1632_XN.getStart());
|
||||
}
|
||||
|
||||
static final private BigInteger NCR1632_MASK_PAGE = BigInteger.valueOf(0x1FF);
|
||||
static final private BigInteger NCR1632_MASK_MAX = new BigInteger("FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF"+"FFFFFFFFFFFFFFFFFF", 16);
|
||||
|
||||
static private List<Integer> embedNCR1632Value(List<Integer> result, BigInteger value, int bankStart) {
|
||||
if (value.equals(BigInteger.ZERO)) {
|
||||
throw new IllegalArgumentException("The value ZERO is not allowed.");
|
||||
}
|
||||
//if (value.signum() == -1) {
|
||||
// // TODO: check if we need one octal for pos/neg/qNaN/sNaN/pos_inf/neg_inf/free/free options
|
||||
//}
|
||||
List<Integer> result = new ArrayList<>();
|
||||
if (value.and(NCR1632_MASK_MAX).equals(BigInteger.ZERO)) {
|
||||
throw new IllegalArgumentException("Value is larger than 576 bit: " + value);
|
||||
}
|
||||
BigInteger valueZero = value.subtract(BigInteger.ONE);
|
||||
if (valueZero.equals(BigInteger.ZERO)) {
|
||||
result.add(bankStart);
|
||||
return result;
|
||||
}
|
||||
BigInteger pageSize = BigInteger.valueOf(0x1FF);
|
||||
BigInteger reminder = valueZero;
|
||||
|
||||
for (int i = 63; i >= 0; i--) {
|
||||
int bankValue = valueZero.shiftRight(i * 9).and(pageSize).intValue();
|
||||
int bankValue = valueZero.shiftRight(i * 9).and(NCR1632_MASK_PAGE).intValue();
|
||||
if (bankValue == 0) {
|
||||
continue;
|
||||
}
|
||||
int cakePoint = bankStart + bankValue + (i * 512);
|
||||
result.add(cakePoint);
|
||||
reminder = reminder.subtract(BigInteger.valueOf(bankValue).shiftLeft(i * 9));
|
||||
}
|
||||
if (!reminder.equals(BigInteger.ZERO)) {
|
||||
throw new IllegalArgumentException("Value is larger than 576 bit: " + reminder + " of " + value);
|
||||
result.add(cakePoint);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ public class FourCornerZionStenoGrapher {
|
|||
|
||||
@Override
|
||||
public void strobeNCR1632(BigInteger denominator, BigInteger numerator) {
|
||||
out.addAll(FourCornerRecipe.embedNCR1632Denominator(denominator));
|
||||
out.addAll(FourCornerRecipe.embedNCR1632Numerator(numerator));
|
||||
FourCornerRecipe.embedNCR1632Denominator(out, denominator);
|
||||
FourCornerRecipe.embedNCR1632Numerator(out, numerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue