0

Last step for me when finishing a JS code is letting it run trough JSLint. I forgot a few semicolons and the radix parameters at parseInt(). Well, these issues were solved quickly.

But now I'm curious: Why would we need binary, octal or hexadecimal radixes? I couldn't find anything in Google.

Can anyone probably give an example?

Note: I'm not asking what are these radixes based on or how they look like, I'm actually looking for a scenario where you would need others than the decimal. Thanks.

Norman
  • 785
  • 7
  • 27
  • If you know the string you are parsing contains a number in hexadecimal, e.g. `"123ABC"` then you need a hexadecimal radix to parse it correctly. There are any number of possible use cases for numbers that aren't base 10. However, that's not why JSLint wants you to supply a radix to `parseInt()`, JSLint wants you to specify the radix (in most cases you'd need 10) because if you don't then the default behaviour is (or was) to guess the required base according to the input string. – nnnnnn Jul 03 '15 at 07:49
  • possible duplicate of [In what situations is octal base used?](http://stackoverflow.com/questions/2609426/in-what-situations-is-octal-base-used) – t3dodson Jul 03 '15 at 07:49
  • @nnnnnn Ah, like parsing `#ffffff` to `rgb(255,255,255)`? – Norman Jul 03 '15 at 07:51
  • possible duplicate of [Using Javascript parseInt() and a Radix Parameter](http://stackoverflow.com/questions/10398834/using-javascript-parseint-and-a-radix-parameter) – Jaffer Wilson Jul 03 '15 at 07:52
  • @t3dodson Ok, the Unix thingy helped. – Norman Jul 03 '15 at 07:54
  • @Norman next time try to make your question more clear than now...ok – Jaffer Wilson Jul 03 '15 at 08:38

1 Answers1

0

Well, let me sum this up: I guess you won't need most of them in JavaScript, which I am most familiar to and therefore it's "the language I'm thinking in".

Where you probably will need the hexadecimal radix is, when you want to convert a hexadecimal color code like #ffffff to an RGB color code.

The octal radix is useful regarding the Unix file permissions, but I read somewhere that it's deprecated in JavaScript. I can't imagine to have permission stuff running in JS anyway because would be a huge security issue. Or maybe just read only to output the permissions in the frontend.

I couldn't find anything why we should use a binary radix though. Maybe someone can add a comment.

Norman
  • 785
  • 7
  • 27