Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:51:07+00:00 2026-06-10T21:51:07+00:00

I am trying to convert a DEC number to HEX using JavaScript. The number

  • 0

I am trying to convert a DEC number to HEX using JavaScript.

The number I am trying to convert is 28.

I have tried using:

function h2d(h) {return parseInt(h,16);}

however it returns 40

I have also tried using:

function d2h(d) {return d.toString(16);}

however it returns 28

The final result should return 1C but I can’t seem to work it out.

Does anyone know where I have gone wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:51:08+00:00Added an answer on June 10, 2026 at 9:51 pm

    It sounds like you’re having trouble because your input is a String when you’re looking for a number. Try changing your d2h() code to look like this and you should be set:

    function d2h(d) { return (+d).toString(16); }
    

    The plus sign (+) is a shorthand method for forcing a variable to be a Number. Only Number’s toString() method will take a radix, String’s will not. Also, your result will be in lowercase, so you might want to force it to uppercase using toUpperCase():

    function d2h(d) { return (+d).toString(16).toUpperCase(); }
    

    So the result will be:

    d2h("28") //is "1C"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to convert this php function to javascript: function sanitize_words($string,$limit=false) { preg_match_all(/\p{L}[\p{L}\p{Mn}\p{Pd}'\x{2019}]{1,}/u,$string,$matches,PREG_PATTERN_ORDER); return
I'm trying to convert dates using as.POSIXct dates <- c(1-DEC-2011 00:56:06.82, 1-DEC-2011 01:29:57.07, 1-DEC-2011
i´m using subsonic 3 trying convert a SQL2008 project to MySQL. when the projects
Trying to convert my local SVN repo to Git using svn2git as suggested by
I'm trying to get the value of a number to 2 dec places from
I'm using lambda expression and trying convert into uint while adding into the Hashset.
I have an XML file and I'm trying convert it into a (table( HTML
Trying to convert a perl script to php. In perl I have a hash
Trying to convert some VB to C#... (learning C#, too). I have some code
Trying to convert a JSON string into an object in C#. Using a really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.