Decimal conversion to binary:
var num = 100;console.log(num.toString(2));
The ToString () method converts a Number object to a string and returns the result.
Grammar
NumberObject.toString(radix);
Among them, Radix is optional. An integer that specifies the cardinality of the number that makes 2 ~ 36. If this argument is omitted, cardinality 10 is used. Note, however, that if the parameter is a value other than 10, the ECMAScript standard allows the implementation to return any value.
return value
A string of numbers. For example, when Radix is 2 o'clock, Numberobject is converted to a string represented by a binary value.
Thrown
The TypeError exception is thrown when the object calling the method is not number.
Binary goto decimal:
var num = 1100100;console.log(parseInt(num,2));
The parseint () function parses a string and returns an integer.
Grammar
parseInt(string, radix);
where string is required. The string to be parsed. Radix is optional. Represents the cardinality of the number to parse. The value is between 2 and 36. If this argument is omitted or its value is 0, the number is parsed based on 10. If it starts with "0x" or "0X", it will have a base of 16. If the parameter is less than 2 or greater than 36, parseint () returns NaN.
return value
Returns the parsed number.
Description
When the value of the parameter radix is 0, or if the parameter is not set, parseint () determines the cardinality of the number based on string.
For example, if string starts with "0x", parseint () resolves the remainder of the string to a 16-binary integer. If string starts with 0, then ECMAScript V3 allows an implementation of parseint () to parse subsequent characters into octal or hexadecimal digits. If string starts with a number from 1 to 9, parseint () parses it into a decimal integer.
Hints and Notes
Note: only the first number in a string is returned.
Note: spaces at the beginning and end are allowed.
Tip: If the first character of a string cannot be converted to a number, parsefloat () returns NaN.
parseint (NUM,8);Octal goto Decimalparseint (NUM,16);Hexadecimal goto Decimalparseint (num). toString (8)Decimal Turn octalparseint (num). toString (16)Decimal Turn hexparseint (NUM,2). ToString (8) //binary to octal parseint (Num,2). ToString (16) //binary turn hex parseint (Num,8). ToString ( 2) //octal to binary parseint (Num,8). ToString (16) //octal to hex parseint (Num,16). ToString (2) //hex-binary parseint (Num,16). ToString (8) //hex to octal
JS numeric binary cross-transfer