Perl中的hex函數將給定的十六進製數(以16為底)轉換為其等效的十進製數(以10為底)。
用法: hex number
參數:
number:要轉換的十六進製數
返回值:給定十六進製數的等效十進製數。
示例1:
#!/usr/bin/perl
# Initialising some hexadecimal values for
# the parameter of the hex function
$A = "A";
$B = "B";
$C = "1A";
$D = "2C";
# Calling the hex function
$E = hex $A;
$F = hex $B;
$G = hex $C;
$H = hex $D;
# Getting the equivalent decimal number
# of the given hexadecimal number
print "$E\n";
print "$F\n";
print "$G\n";
print "$H\n";
輸出:
10 11 26 44
示例2:
#!/usr/bin/perl
# Initialising some hexadecimal values and
# Calling the hex function
$A = hex D;
$B = hex af;
$C = hex AF;
$D = hex BF;
# Getting the equivalent decimal number
# of the given hexadecimal number
print "$A\n";
print "$B\n";
print "$C\n";
print "$D\n";
輸出:
13 175 175 191
相關用法
- Perl uc()用法及代碼示例
- Perl each()用法及代碼示例
- Perl sin()用法及代碼示例
- Perl oct()用法及代碼示例
- Perl ord()用法及代碼示例
- Perl log()用法及代碼示例
- Perl int()用法及代碼示例
- Perl abs()用法及代碼示例
- Perl exp用法及代碼示例
- Perl cos()用法及代碼示例
- Perl tell()用法及代碼示例
- Perl chr()用法及代碼示例
- Perl rindex()用法及代碼示例
- Perl join()用法及代碼示例
- Perl keys()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Perl | hex Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。