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

ES6 进制字面量 All In One

ES6 进制字面量 All In One

二进制 & 八进制 & 字面量

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

二进制字面量 & 八进制字面量

  1. 二进制使用 0b 或 0B 开头

const  binary10 = 0b10; 
const Binary10 = 0B10; 

log(binary10); 
// 2
log(Binary);
// 2

  1. 八进制使用 0o 或 0O 开头
const log = console.log;

const Octal10 = 0o10;

log(Octal10); 
// 8

// ??? 八进制使用 00 开头
let x = 0010;
// 8

x = 0o10;
// 8

x = 0O10;
// 8

Number.prototype.toString()

numObj.toString([radix])

const num = 8;

num.toString(10);
// "8"

num.toString(8);
// "10"

num.toString(2);
// "1000"

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString

parseInt()

parseInt(string [, radix])


const str = `10`;

parseInt(str, 2);
// 2

parseInt(str, 8);
// 8

parseInt(str, 10);
// 10

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

Numbers and dates

  1. Binary number

(0b or 0B)

二进制

  1. Octal number

(0o or 0O) / 00

八进制

  1. Hexadecimal numbers

(0x or 0X)

十六进制

  1. Decimal numbers

小数/分数

  1. Exponentiation

指数


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Numbers_and_dates

refs

https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data



©xgqfrms 2012-2020

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


posted @ 2020-10-19 15:27  xgqfrms  阅读(133)  评论(3编辑  收藏  举报