xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js base number All In One

js base number All In One

js 进制数


class UFO {
  public name: string = '';
  private id?: number = 0;
  constructor(name: string, id?: number) {
    this.name = name;
    if (id) {
      this.id = id;
    }
  }
  protected getName() {
    console.log(`UFO name = ${this.name}`);
  }
  getId() {
    console.log('UFO id =', this.id);
  }
  getAll() {
    this.getName();
    this.getId();
  }
}


// const ufo = new UFO('ufo', 007);
/*

Octal literals are not allowed in strict mode.ts(1121)
Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o7'.ts(1085)
*/

const ufo = new UFO('ufo', 7);
const ufo_binary = new UFO('ufo', 0b111);
const ufo_octal = new UFO('ufo', 0o007);
const ufo_hex = new UFO('ufo', 0x007);



ufo.name;
ufo.getId();
// ufo.getName();
// Property 'getName' is protected and only accessible within class 'UFO' and its subclasses.ts(2445)
ufo.getAll();


Binary number

二进制数

0~1

var FLT_SIGNBIT  = 0b10000000000000000000000000000000; // 2147483648
var FLT_EXPONENT = 0b01111111100000000000000000000000; // 2139095040
var FLT_MANTISSA = 0B00000000011111111111111111111111; // 8388607


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#binary

Octal number

八进制数
0~7


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#octal

Hexadecimal number

十六进制数

0~F

0xFFFFFFFFFFFFFFFFF;
// 295147905179352830000

0x123456789ABCDEF;
// 81985529216486900

0XA;
// 10


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#hexadecimal

BigInt literal


123456789123456789n;
// 123456789123456789

0o777777777777n;
// 68719476735

0x123456789ABCDEFn;
// 81985529216486895

0b11101001010101010101n;
// 955733

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#bigint_literal

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#bigint_type

refs



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-02-06 23:25  xgqfrms  阅读(37)  评论(2编辑  收藏  举报