What is the hexadecimal equivalent of number 264 and 140 ? Please give me full coding of this program.
Did you do that by hand, or did you use the Calculator applet?
John Saunders
2009-08-16 05:36:12
With the calculator of course. As a programmer I am obviously lazy.
Noon Silk
2009-08-16 05:43:42
Hmm, maybe you had better do it programmatically after all. `s/246/264/`
Tim Sylvester
2009-08-16 06:32:06
Right you are; though the hex was correct :) Corrected.
Noon Silk
2009-08-16 06:41:15
+7
A:
You can use the toString function on numbers, and pass the base to be converted:
(264).toString(16); // 108 hex
(140).toString(16); // 8c hex
And to do the opposite, you can use the parseInt function:
parseInt('108', 16); // 264 dec
parseInt('8c', 16); // 140 dec
CMS
2009-08-16 05:37:26
+1
A:
If you didn't know, you can use Google to convert decimal to hexadecimal or vice versa.
But it looks like @CMS already posted the Javascript code for you :) +1 to him.
Mark Rushakoff
2009-08-16 05:39:17
+1
A:
Since this is a Homework question, I am guessing that the questioner may be looking for an algorithm.
This is some C# code that does this without special functions:
int x = 140;
string s = string.Empty;
while (x != 0)
{
int hexadecimal = x % 16;
if (hexadecimal < 10)
s = hexadecimal.ToString() + s;
else
s = ((char)('A' + (char)(hexadecimal - 10))).ToString() + s;
x = (int)(x / (int)16);
}
MessageBox.Show("0X" + s);
Since this is homework, you can figure out how to translate this into JavaScript
jrcs3
2009-08-16 05:59:54