Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Converting a Decimal to a Hexadecimal Value

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 195
    Comment on it


    Hello readers in this blog we will discuss about the conversion of a decimal into a hexadecimal value. In this case if we have a decimal value. we have to find its hexadecimal equivalent, we use the Number object’s toString method :-

    Syntax:-

    var num = 255;
    alert(num.toString(16)); // displays ff, which is hexadecimal equivalent for 255

     

    The default javascript numbers are base 10, or deciaml. hexadecimal and octal notation can be used and created.

     

     Hexadecimal numbers begin with 0x (a zero followed by lowercase x), and octal numbers always begin with zero:
     

    Syntax:-

    var octoNumber = 0255; // equivalent to 173 decimal
    var hexaNumber = 0xad; // equivalent to 173 decimal

     

    By using the Number object’s toString method other base numbers can be created. By passing in the base radix, in a range from 2 to 36:

     

    Syntax:-

    var decNum = 55;
    var octNum = decNum.toString(8); // value of 67 octal
    var hexNum = decNum.toString(16); // value of 37 hexadecimal
    var binNum = decNum.toString(2); // value of 110111 binary

     

    You need to concentrate the zero to the octal, and the 0x to the hexadecimal value if you want to complete the octal and hexadecimal presentation. Base number (between a range of 2 to 36) can be changed over by decimals just the octal, hexadecimal, and decimal numbers can be controlled, straightforwardly, as numbers.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: