Go Go lu
Go Go lu

Reputation: 311

Converting binary to hexadecimal

I am converting binary to hexadecimal but the code below returns a wrong answer:

var number = 1011;
var hexa = parseInt(number, 2).toString(16);
return hexa;

This returns b but it should have to be return B. What is the problem?

Upvotes: 15

Views: 35046

Answers (2)

Lukasz Czerwinski
Lukasz Czerwinski

Reputation: 15482

Just add toUpperCase():

var hexa = parseInt(number, 2).toString(16).toUpperCase();

Upvotes: 14

rsjaffe
rsjaffe

Reputation: 5730

'b' is correct. Hexadecimal doesn't specify letter case, and many write hex strings with lower-case letters.

Upvotes: 21

Related Questions