0

I wish to convert the whiteHex variable to a decimal using the parseInt() function, and store it in a variable, whiteDecimal.

var whiteHex = 'ffffff';

var whiteDecimal = parseInt(whiteHex);

I am unsure if the above is correct or not. The reason being, that I then wish to subtract 1 from whiteDecimal and store it in a variable offWhiteDecimal. This is where I am getting stuck. How can I subtract one from the ffffff hex value? Am I missing something within the parseInt function?

ThanhPhanLe
  • 1,315
  • 3
  • 14
  • 25

1 Answers1

2

You're looking for this:

var whiteDecimal = parseInt(whiteHex, 16)
console.log(whiteDecimal - 1);

ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt#Syntax

Nickolay
  • 31,095
  • 13
  • 107
  • 185