Converting a variable to hex and binary

C

Cogito

Is there a javascript command to convert and display a variable in
hexadecimal and/or in binary?
 
C

Cogito

It's not a command, it's a method.

var num = 42;
var hex = num.toString(16);
alert(hex);
alert(num.toString(2));

Thanks.
Now I know the method and the correct javascript parlance.
 
N

nice.guy.nige

While the city slept said:
It's not a command, it's a method.
[...]

Hang on... first your say "Yes" to the question "Is there a [...] command",
then you say "It's not a command"... so your first post was wrong? ;-)

Cheers,
Nige

--
Nigel Moss.

Email address is not valid. (e-mail address removed). Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
 
R

rf

It's not a command, it's a method.
[...]

Hang on... first your say "Yes" to the question "Is there a [...] command",
then you say "It's not a command"... so your first post was wrong? ;-)

Absolutely.

Good to see there are *some* sharp people still here :)
 
A

Andy Dingley

Cogito said:
Is there a javascript command to convert and display a variable in
hexadecimal and/or in binary?

Number.toString (radix)

Just give it the value of radix that you want - 16 or 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top