PHP数学运算代码转换成asp代码
今天考试过后(考的很悲剧),逛论坛看见一贴,说是转换一段asp代码为php代码:
01 <?php
02 function app_hash_url($url) {
03 $seed = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE.";
04 $result = 0x01020345;
05 for ($i=0; $i<strlen($url); $i++) {
06 $result ^= ord($seed{$i%87}) ^ ord($url{$i});
07 $result = (($result >> 23) & 0x1FF) | $result << 9;
08 }
09 return sprintf("8%x", $result);
10 }
11 $url="dddddd";
12 echo app_hash_url($url);
13 ?>
转换如下:
1.asp没有位移运算,百度了一个位移运算的类
2.格式化输出
01 <%
02 Class mShift
03
04 Private m_lPower2(31)
05
06 Public Function RShift(ByVal lThis, ByVal lBits)
07 On Error Resume Next
08 Init
09 If (lBits <= 0) Then
10 RShift = lThis
11 ElseIf (lBits > 63) Then
12 ' .. error ...
13 ElseIf (lBits > 31) Then
14 RShift = 0
15 Else
16 If (lThis And m_lPower2(31 - lBits)) = m_lPower2(31 - lBits) Then
17 RShift = (lThis And (m_lPower2(31 - lBits) - 1)) * m_lPower2(lBits)Or m_lPower2(31)
18 Else
19 RShift = (lThis And (m_lPower2(31 - lBits) - 1)) * m_lPower2(lBits)
20 End If
21 End If
22 End Function
23
24 Public Function LShift(ByVal lThis, ByVal lBits)
25 On Error Resume Next
26 Init
27 If (lBits <= 0) Then
28 LShift = lThis
29 ElseIf (lBits > 63) Then
30 ' ... error ...
31 ElseIf (lBits > 31) Then
32 LShift = 0
33 Else
34 If (lThis And m_lPower2(31)) = m_lPower2(31) Then
35 LShift = (lThis And &H7FFFFFFF) \ m_lPower2(lBits) Or m_lPower2(31 - lBits)
36 Else
37 LShift = lThis \ m_lPower2(lBits)
38 End If
39 End If
40 End Function
41
42 Private Sub Init()
43 On Error Resume Next
44 m_lPower2(0) = &H1&
45 m_lPower2(1) = &H2&
46 m_lPower2(2) = &H4&
47 m_lPower2(3) = &H8&
48 m_lPower2(4) = &H10&
49 m_lPower2(5) = &H20&
50 m_lPower2(6) = &H40&
51 m_lPower2(7) = &H80&
52 m_lPower2(8) = &H100&
53 m_lPower2(9) = &H200&
54 m_lPower2(10) = &H400&
55 m_lPower2(11) = &H800&
56 m_lPower2(12) = &H1000&
57 m_lPower2(13) = &H2000&
58 m_lPower2(14) = &H4000&
59 m_lPower2(15) = &H8000&
60 m_lPower2(16) = &H10000
61 m_lPower2(17) = &H20000
62 m_lPower2(18) = &H40000
63 m_lPower2(19) = &H80000
64 m_lPower2(20) = &H100000
65 m_lPower2(21) = &H200000
66 m_lPower
相关新闻>>
- 发表评论
-
- 最新评论 更多>>