MCPcopy Create free account
hub / github.com/Marus/cortex-debug / toStringDecHexOctBin

Function toStringDecHexOctBin

src/common.ts:527–563  ·  view source on GitHub ↗
(val: number/* should be an integer*/)

Source from the content-addressed store, hash-verified

525}
526
527export function toStringDecHexOctBin(val: number/* should be an integer*/): string {
528 if (Number.isNaN(val)) {
529 return 'NaN: Not a number';
530 }
531 if (!Number.isSafeInteger(val)) {
532 // TODO: Handle bigNum's. We eventually have to. We need to use bigint as javascript
533 // looses precision beyond 53 bits
534 return 'Big Num: ' + val.toString() + '\nother-radix values not yet available. Sorry';
535 }
536
537 let ret = `dec: ${val}`;
538 if (val < 0) {
539 val = -val;
540 val = (~(val >>> 0) + 1) >>> 0;
541 }
542 let str = val.toString(16);
543 str = '0x' + '0'.repeat(Math.max(0, 8 - str.length)) + str;
544 ret += `\nhex: ${str}`;
545
546 str = val.toString(8);
547 str = '0'.repeat(Math.max(0, 12 - str.length)) + str;
548 ret += `\noct: ${str}`;
549
550 str = val.toString(2);
551 str = '0'.repeat(Math.max(0, 32 - str.length)) + str;
552 let tmp = '';
553 while (true) {
554 if (str.length <= 8) {
555 tmp = str + tmp;
556 break;
557 }
558 tmp = ' ' + str.slice(-8) + tmp;
559 str = str.slice(0, -8);
560 }
561 ret += `\nbin: ${tmp}`;
562 return ret ;
563}
564
565export function parseHostPort(hostPort: string) {
566 let port: number;

Callers 4

registersRequestMethod · 0.90
getTreeItemMethod · 0.90
getTreeItemMethod · 0.90
createToolTipMethod · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected