How to convert Hexadecimal, octal,binary

     In javascript we can easy to convert any numbers to corespoinding hexadecimal, octal or binary value using toString() method.

Syntax

   variable.toString()      //convert to String
   variable.toString(2)    //convert to Binary
   variable.toString(8)    //convert to Octal
   variable.toString(16)  //convert to Hexadecimal

Example

   var num=66;
   num.toString();     //return "66"
   num.toString(2);   //return "1000010"
   num.toString(8);   //return "102"
   num.toString(16); //return "42"


Example Program:- (Editor)


Editor is Loading...

Advertisement

0 nhận xét:

Đăng nhận xét