Subversion Repositories php-qbpwcf

Rev

Rev 226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
226 liveuser 22
 
3 liveuser 23
*/
24
 
25
/*
26
將兩個16進未數值進行運算
27
*/
28
 
29
#如果不存在要轉換成16進位的數值
30
if( !isset($_SERVER['argv'][1]) || !isset($_SERVER['argv'][2]) || !isset($_SERVER['argv'][3]) )
31
{
32
	#show help
33
	help();
34
 
35
	#停止執行
36
	exit;
37
}
38
 
39
#取得10進位的兩個數字
40
$num1=base_convert($_SERVER['argv'][1],16,10);
41
$num2=base_convert($_SERVER['argv'][3],16,10);
42
 
43
#取得運算符號
44
$op=$_SERVER['argv'][2];
45
 
46
#判斷運算符號
47
switch($op)
48
{
49
	#如果是加法
50
	case "+":
51
			$result=$num1+$num2;
52
		break;
226 liveuser 53
 
3 liveuser 54
	#如果是減法
55
	case "-":
56
			$result=$num1-$num2;
57
		break;
226 liveuser 58
 
3 liveuser 59
	#如果是乘法
60
	case "x":
61
			$result=$num1*$num2;
62
		break;
226 liveuser 63
 
64
	#如果是除法
3 liveuser 65
	case "/":
66
			$result=$num1/$num2;
67
		break;
226 liveuser 68
 
3 liveuser 69
	#其他運算符號
70
	default:
226 liveuser 71
 
3 liveuser 72
		#show help
73
		help();
226 liveuser 74
 
3 liveuser 75
		#停止執行
76
		exit;
77
}
78
 
79
#印出 16 進位的數值
80
echo sprintf('%X',$result).PHP_EOL;
81
 
82
#help function
83
function help()
84
{
85
	echo $_SERVER['argv'][0]." 16進位數值 [+,-,*,/] 16進位數值".PHP_EOL;
86
}
87
 
88
?>