Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.5 KiB
Raw Permalink Blame History

id, title, challengeType, dashedName
id title challengeType dashedName
68c497f3aaefc9fd9f1b0e26 Challenge 62: Hex to Decimal 28 challenge-62

--description--

Given a string representing a hexadecimal number (base 16), return its decimal (base 10) value as an integer.

Hexadecimal is a number system that uses 16 digits:

  • 0-9 represent values 0 through 9.
  • A-F represent values 10 through 15.

Here's a partial conversion table:

Hexadecimal Decimal
0 0
1 1
... ...
9 9
A 10
... ...
F 15
10 16
... ...
9F 159
A0 160
... ...
FF 255
100 256
  • The string will only contain characters 09 and AF.

--hints--

hexToDecimal("A") should return 10.

assert.equal(hexToDecimal("A"), 10);

hexToDecimal("15") should return 21.

assert.equal(hexToDecimal("15"), 21);

hexToDecimal("2E") should return 46.

assert.equal(hexToDecimal("2E"), 46);

hexToDecimal("FF") should return 255.

assert.equal(hexToDecimal("FF"), 255);

hexToDecimal("A3F") should return 2623.

assert.equal(hexToDecimal("A3F"), 2623);

--seed--

--seed-contents--

function hexToDecimal(hex) {

  return hex;
}

--solutions--

function hexToDecimal(hex) {

  return parseInt(hex, 16);
}