0

I've got this statement in javascript:

<script>
alert((444).toString(16));
</script>

Why is the output 1bc ? I tried in .net it gives 16, i don't understand can someone help me ?

Jorge
  • 17,896
  • 19
  • 80
  • 126
dmc
  • 13
  • 1
  • 4

1 Answers1

4

The output 1bc is 444 in base 16 (hexidecimal). In other words, the Number.toString method in JavaScript takes an optional base (radix) for the output conversion. In contrast, C#'s Int32.ToString method takes a format string.

If you want format strings in JavaScript, you can look at the answers for the question JavaScript equivalent to printf/string.format (the answer I linked to suggests a JS library providing an sprintf function).

Community
  • 1
  • 1
DaoWen
  • 32,589
  • 6
  • 74
  • 101
  • Thank you DaeWen just figured it out. – dmc Jun 27 '13 at 20:48
  • Convert.ToString(444, 16) in .net – dmc Jun 27 '13 at 20:48
  • You could probably also do something like (444).ToString("x") in .NET (I think that's how you'd call it based off [this page](http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx)). Also, you can click the green checkmark to accept my answer if it answered your question. :) – DaoWen Jun 27 '13 at 20:56