當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Perl hex用法及代碼示例


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


相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Perl | hex Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。