Files
BitwiseCmd/app/bitwise/formatter.js
Borys Levytskyi d96bcb0517 Introduced core.
2015-04-04 16:33:33 +03:00

33 lines
745 B
JavaScript

(function(should, app){
app.compose(function() {
var should = app.get('should');
app.set("formatter", {
toBinaryString: function(num, totalLength) {
var binaryStr = num.toString(2),
formatted = [],
i;
if(totalLength != null) {
should.bePositiveInteger(totalLength);
}
for(i = 0; i<binaryStr.length; i++) {
formatted.push(binaryStr[i]);
}
while(totalLength > formatted.length) {
formatted.unshift('0');
}
return formatted.join('');
}
});
})
})(window.should, window.app);