Pad with zeroes

This commit is contained in:
BorysLevytskyi
2016-11-22 19:48:10 +02:00
parent fdf6e5dd9b
commit bece4ffc8d
5 changed files with 65 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
import * as _ from 'lodash';
var expression = {
factories:[],
canParse: function(string) {
@@ -119,6 +121,7 @@ export class Operand {
this.bin = this.value < 0 ? (this.value >>> 0).toString(2) : this.value.toString(2);
this.kind = this.input.indexOf('0x') > -1 ? 'hex' : 'dec';
this.other = this.kind == 'dec' ? this.hex : this.dec;
this.lengthInBits = Operand.getBitLength(this.value);
}
getLengthInBits() {
@@ -154,6 +157,10 @@ export class Operand {
return this.input;
}
static getBitLength(num) {
return Math.floor(Math.log(num) / Math.log(2)) + 1
}
static getBase(kind){
switch (kind){
case 'bin': return 2;
@@ -223,6 +230,7 @@ export class ListOfNumbersExpression {
constructor(expressionString, numbers) {
this.expressionString = expressionString;
this.numbers = numbers;
this.maxBitsLegnth = _.chain(numbers).map(n => n.lengthInBits).reduce((n , c) => n >= c ? n : c, 0).value();
}
}