mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-22 04:32:49 +01:00
33 lines
745 B
JavaScript
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);
|
|
|
|
|