PB中位操作的實現程式碼
(三)編寫公用函式以逐位獲取BIT位資料:
public function boolean of_getbit (long al_decimal, unsignedinteger ai_bit);Boolean lb_null
If IsNull(al_decimal) or IsNull(ai_bit) then
SetNull(lb_null)
Return lb_null
End If
If Int(Mod(al_decimal / (2 ^(ai_bit - 1)), 2)) > 0 Then
Return True
End If
Return False
end function
(四)編寫AND與操作函式:
public function long of_bitwiseand (long al_value1, long al_value2);Integer li_Cnt
Long ll_Result
Boolean lb_Value1[32], lb_Value2[32]
If IsNull(al_Value1) Or IsNull(al_Value2) Then
SetNull(ll_Result)
Return ll_Result
End If
For li_Cnt = 1 To 32
lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
Next
For li_Cnt = 1 To 32
If lb_Value1[li_Cnt] And lb_Value2[li_Cnt] Then
ll_Result = ll_Result + (2^(li_Cnt - 1))
End If
Next
Return ll_Result
end function
(五)編寫OR或操作函式:
public function long of_bitwiseor (long al_value1, long al_value2);Integer li_Cnt
Long ll_Result
Boolean lb_Value1[32], lb_Value2[32]
If IsNull(al_Value1) Or IsNull(al_Value2) Then
SetNull(ll_Result)
Return ll_Result
End If
For li_Cnt = 1 To 32
lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
Next
For li_Cnt = 1 To 32
If lb_Value1[li_Cnt] Or lb_Value2[li_Cnt] Then
ll_Result = ll_Result + (2^(li_Cnt - 1))
End If
Next
Return ll_Result
end function
(六)編寫XOR異或操作函式:
public function long of_bitwisexor (long al_value1, long al_value2);Integer li_Cnt
Long ll_Result
Boolean lb_Value1[32], lb_Value2[32]
If IsNull(al_Value1) Or IsNull(al_Value2) Then
SetNull(ll_Result)
Return ll_Result
End If
For li_Cnt = 1 To 32
lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
Next
For li_Cnt = 1 To 32
If (lb_Value1[li_Cnt] And Not lb_Value2[li_Cnt]) Or &
(Not lb_Value1[li_Cnt] And lb_Value2[li_Cnt]) Then
ll_Result = ll_Result + (2^(li_Cnt - 1))
End If
Next
Return ll_Result
end function
(七)編寫NOT否操作函式:
public function long of_bitwisenot (long al_value);Integer li_Cnt, li_Count
Long ll_Result
string ls_Value, ls_Result
If IsNull(al_Value) Then
SetNull(ll_Result)
Return ll_Result
End If
ls_Value = of_binary(al_Value)
li_Cnt = Len(ls_Value)
For li_Count = 1 To li_Cnt
If Mid(ls_Value, li_Count, 1) = '0' Then
ls_Result = ls_Result + '1'
Else
ls_Result = ls_Result + '0'
End If
End For
Return of_decimal(ls_Result)
end function
(八)呼叫上述函式:
//將十進位制數10轉換為二進位制1010
ls_binary = of_binary(10)
//將二進位制1010轉換為十進位制數10
ll_decimal = of_decimal(“1010”)
//執行AND與操作(55 && 44) = 36
ll_ret = of_bitwiseand(55,44) //返回36
//執行NOT否操作(! 55) = 8
ll_ret = of_bitwisenot(55) //返回8
//執行OR或操作(55 ¦ ¦ 44) = 63
ll_ret = of_bitwiseor(55,44) //返回63
//執行XOR異或操作(55 XOR 44) = 27
ll_ret = of_bitwisexor(55,44) //返回27[@more@]
public function boolean of_getbit (long al_decimal, unsignedinteger ai_bit);Boolean lb_null
If IsNull(al_decimal) or IsNull(ai_bit) then
SetNull(lb_null)
Return lb_null
End If
If Int(Mod(al_decimal / (2 ^(ai_bit - 1)), 2)) > 0 Then
Return True
End If
Return False
end function
(四)編寫AND與操作函式:
public function long of_bitwiseand (long al_value1, long al_value2);Integer li_Cnt
Long ll_Result
Boolean lb_Value1[32], lb_Value2[32]
If IsNull(al_Value1) Or IsNull(al_Value2) Then
SetNull(ll_Result)
Return ll_Result
End If
For li_Cnt = 1 To 32
lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
Next
For li_Cnt = 1 To 32
If lb_Value1[li_Cnt] And lb_Value2[li_Cnt] Then
ll_Result = ll_Result + (2^(li_Cnt - 1))
End If
Next
Return ll_Result
end function
(五)編寫OR或操作函式:
public function long of_bitwiseor (long al_value1, long al_value2);Integer li_Cnt
Long ll_Result
Boolean lb_Value1[32], lb_Value2[32]
If IsNull(al_Value1) Or IsNull(al_Value2) Then
SetNull(ll_Result)
Return ll_Result
End If
For li_Cnt = 1 To 32
lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
Next
For li_Cnt = 1 To 32
If lb_Value1[li_Cnt] Or lb_Value2[li_Cnt] Then
ll_Result = ll_Result + (2^(li_Cnt - 1))
End If
Next
Return ll_Result
end function
(六)編寫XOR異或操作函式:
public function long of_bitwisexor (long al_value1, long al_value2);Integer li_Cnt
Long ll_Result
Boolean lb_Value1[32], lb_Value2[32]
If IsNull(al_Value1) Or IsNull(al_Value2) Then
SetNull(ll_Result)
Return ll_Result
End If
For li_Cnt = 1 To 32
lb_Value1[li_Cnt] = of_getbit(al_Value1, li_Cnt)
lb_Value2[li_Cnt] = of_getbit(al_Value2, li_Cnt)
Next
For li_Cnt = 1 To 32
If (lb_Value1[li_Cnt] And Not lb_Value2[li_Cnt]) Or &
(Not lb_Value1[li_Cnt] And lb_Value2[li_Cnt]) Then
ll_Result = ll_Result + (2^(li_Cnt - 1))
End If
Next
Return ll_Result
end function
(七)編寫NOT否操作函式:
public function long of_bitwisenot (long al_value);Integer li_Cnt, li_Count
Long ll_Result
string ls_Value, ls_Result
If IsNull(al_Value) Then
SetNull(ll_Result)
Return ll_Result
End If
ls_Value = of_binary(al_Value)
li_Cnt = Len(ls_Value)
For li_Count = 1 To li_Cnt
If Mid(ls_Value, li_Count, 1) = '0' Then
ls_Result = ls_Result + '1'
Else
ls_Result = ls_Result + '0'
End If
End For
Return of_decimal(ls_Result)
end function
(八)呼叫上述函式:
//將十進位制數10轉換為二進位制1010
ls_binary = of_binary(10)
//將二進位制1010轉換為十進位制數10
ll_decimal = of_decimal(“1010”)
//執行AND與操作(55 && 44) = 36
ll_ret = of_bitwiseand(55,44) //返回36
//執行NOT否操作(! 55) = 8
ll_ret = of_bitwisenot(55) //返回8
//執行OR或操作(55 ¦ ¦ 44) = 63
ll_ret = of_bitwiseor(55,44) //返回63
//執行XOR異或操作(55 XOR 44) = 27
ll_ret = of_bitwisexor(55,44) //返回27[@more@]
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/631872/viewspace-879154/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【PB登陸的實現】
- 在PB應用中實現聲音與動畫 (轉)動畫
- PB列印斑馬條碼程式
- pb錯誤程式碼詳解
- js實現的保留兩位小數程式碼例項JS
- 欄位修改記錄操作日誌的實現
- golang 中,對稱加密的程式碼實現Golang加密
- JavaScript中的繼承及實現程式碼JavaScript繼承
- Torch中的RNN底層程式碼實現RNN
- 怎樣在PB中實現檔案的複製與刪除 (轉)
- linux中實現檔案的複製(c程式碼實現)LinuxC程式
- Pb中多使用者許可權管理實現方案 (轉)
- 【PB】PB程式設計通俗快速入手程式設計
- 程式碼實現中卡了很久的問題
- js實現的使用鍵盤操作div位置程式碼例項JS
- PB程式碼動態解析執行器
- verilog 中實現 sram 程式碼
- Java中的按位操作——Java程式設計思想筆記Java程式設計筆記
- 正則實現個位數補零程式碼例項
- 用C#程式碼實現二進位制與十進位制的互相轉換C#
- js實現的十進位制和十六進位制相互轉換程式碼例項JS
- js實現的在個位數字前面加0程式碼例項JS
- 相親交友原始碼中,音訊AAC解碼的實現程式碼原始碼音訊
- java Integer中的方法解析(位操作)Java
- 在程式碼中實現android:tint效果Android
- 2,javase程式碼實戰-運算子——位運算實現加密解密 (一)Java加密解密
- 使用純粹的ABAP位操作實現兩個整數相加
- 資料結構中的線性表程式碼實現資料結構
- 新姿勢!Redis中呼叫Lua指令碼以實現原子性操作Redis指令碼
- 原生javascript實現的隨機生成4位字串程式碼例項JavaScript隨機字串
- js實現的數字每隔3位就加逗號程式碼例項JS
- 正規表示式實現的數字千分位程式碼例項
- 在Oracle中實現定時操作Oracle
- 【Kein】ASP.NET2.0中文驗證碼的實現程式碼ASP.NET
- pb實現列印中人民幣大寫 (轉)
- Android中SurfaceView視訊播放實現程式碼AndroidView
- Java 常見記憶體溢位異常與程式碼實現Java記憶體溢位
- web前端入門到實戰:JS中new操作符原始碼實現Web前端JS原始碼