
_START_ARTICLE_
十六进制
_START_SECTION_
十进制转十六进制
_START_PARAGRAPH_
采余数定理分解，例如将4877₁₀转成十六进制：_NEWLINE_4877÷16=304....13(D)_NEWLINE_304÷16=19....0_NEWLINE_19÷16=1....3_NEWLINE_1÷16=0....1_NEWLINE_这样就计到4877₁₀=130D₁₆
_START_SECTION_
Javascript
_START_PARAGRAPH_
Javascript 能以toString() 函数来将十进制数字转为其他任意进制格式（String类型）_NEWLINE_var num = 255;num.toString(16); // 將之轉為十六進制_NEWLINE_亦可用parseInt() 函数将任意进制的字串转为十进制数字_NEWLINE_var hexNum = "FF";parseInt(hexNum, 16); // 將十六進制轉為10進制
_START_SECTION_
Perl
_START_PARAGRAPH_
十进制转十六进制：_NEWLINE_ #!/usr/local/bin/perl_NEWLINE_ # filename: 10to16_NEWLINE_ for ($i = 0; $i < @ARGV; $i++)_NEWLINE_ {_NEWLINE_ printf("%d\t= 0x%x\n", $ARGV[$i], $ARGV[$i]);_NEWLINE_ }_NEWLINE_十六进制转十进制：_NEWLINE_ #!/usr/local/bin/perl_NEWLINE_ # filename: 16to10_NEWLINE_ for ($i = 0; $i < @ARGV; $i++)_NEWLINE_ {_NEWLINE_ $val = hex($ARGV[$i]);_NEWLINE_ printf("0x%x\t= %d\n", $val, $val);_NEWLINE_ }_NEWLINE_用例（类UNIX系统中）：_NEWLINE_先进入以上文件所在的文件夹，然后执行命令：_NEWLINE_> ./10to16 100 512 789_NEWLINE_100= 0x64_NEWLINE_512= 0x200_NEWLINE_789= 0x315_NEWLINE_> ./16to10 AB 5D9_NEWLINE_0xAB= 171_NEWLINE_0x5D9= 1497