Diety Dieticheskie-produkty Protsedury Sredstva Uprajneniya Fitnes Gimnastika Yoga Pitanie Tsellyulit Zdorove Krasota

We humans use Decimal Number System in our daily life whereas our computers use Binary Number System for all of their processing. Sometimes we get into situation where we need to convert some value from one number system to other.

Converting a Decimal value to other Number Systems is dead simple in JavaScript. Let me show you how to do this:

a = 123;

// for binary output
a.toString(2)  // "1111011"

// for octal output
a.toString(8)  // "173"

// for hexadecimal output
a.toString(16) // "7b"

// for base 36 output
a.toString(36) // "3f"

You see how easy it is to convert a value in Decimal Number System to other Number Systems in JavaScript. You can only provide 2 to 36 in toString() as Parameter, other values will create run-time errors.

I hope you like this quick tip.

Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *