注意只能對整型執(zhí)行按位運算。浮點值必須轉換為整型后,才能執(zhí)行按位運算。按位運算采用二進制(以 2 為基)形式計算兩個整數值。它們比較對應位置上的位,然后基于比較的結果賦值。下面的示例演示了 And 運算符。復制Dim x As Integerx = 3 And 5 前面的示例將 x 的值設置為 1。發(fā)生這種情況的原因如下:這些值以二進制形式處理:二進制格式的 3 為 011二進制格式的 5 為 101And 運算符比較這些二進制表示方式,一次比較一個二進制位置(位)。如果給定位置的兩個位都為 1,則將 1 放在結果中的該位置。如果任何一個位是 0,則將 0 放在結果中的該位置。在前面的示例中,按如下所示計算結果:011(二進制格式的 3)101(二進制格式的 5)001(二進制格式的計算結果)計算結果以十進制形式處理。值 001 是 1 的二進制表示形式,因此 x = 1。除了在任何一個比較位是 1 或兩個比較位都是 1 的情況下將 1 賦予結果位以外,按位 Or 運算與此類似。Xor 在比較的位正好只有一個是 1(而不是兩者都是 1)時將 1 賦給結果位。Not 采用單個操作數并反轉所有位(包括符號位),然后將該值賦予結果。這意味著,對于有符號正數,Not 始終返回負值,而對于負數,Not 始終返回正值或零。AndAlso 和OrElse 運算符不支持按位運算。 追問: 好復雜啊...還是不會,還有整數怎么轉換為二進制數? 回答: 為什么一定要用位運算呢,你那個乘法只能通過左移操作符“ ”來進行,而左移一次代表乘以2,要是乘以一個小數,就必須先化成2的n次方,不夠再用加減法調整,很麻煩啊,沒必要用位運算啊。。。 追問: 因為我要進行大量的運算,但速度要快,所有用位運算...我也不想啊.. 回答: 那就不該用VB 啊,c/c++在執(zhí)行效率上是沒話說的。 追問: 問題就是不會嘛... 回答: 那你上csdn上發(fā)帖效果應該不錯 追問: CSDN發(fā)了,我發(fā)在高性能運算,沒人... 回答: 耐心一些,或者你應該發(fā)到VB.NET論壇那里。。。 追問: 額..只能這樣了... 提問者 的感言: 太復雜了..算了 2010-11-08
臨夏網站建設公司創(chuàng)新互聯建站,臨夏網站設計制作,有大型網站制作公司豐富經驗。已為臨夏近千家提供企業(yè)網站建設服務。企業(yè)網站搭建\外貿營銷網站建設要多少錢,請找那個售后服務好的臨夏做網站的公司定做!
我用VB做的你看能不能用
Public b
Public c
Public d
Public e
Public f
Private Sub Command14_Click()
d = ""
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Exit Sub
'c = Text1.Text
If b = "" Then Exit Sub
If e = "+" Then
d = f + b
Else
If e = "-" Then
d = f - b
Else
If e = "*" Then
d = f * b
Else
If e = "/" Then
If b = 0 Then
MsgBox "被除數不能為零!"
Exit Sub
End If
d = f / b
Else
MsgBox "錯誤操作!"
End If
End If
End If
End If
Text1.Text = d
b = ""
c = ""
e = ""
End Sub
Private Sub Command15_Click()
Text1.Text = ""
b = ""
c = ""
d = ""
e = ""
f = ""
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Command1_Click()
'判斷開頭有運算符就清零
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
'判斷開頭有0就禁止輸入數字
If Text1.Text = "0" Then
Else
a = 1
'發(fā)現運算結果就清零
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text '得到當前操作數
End Sub
Private Sub Command2_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 2
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command3_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 3
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command4_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 4
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command5_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 5
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command6_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 6
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command7_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 7
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command8_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 8
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command9_Click()
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
If Text1.Text = "0" Then
Else
a = 9
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
End If
b = Text1.Text
End Sub
Private Sub Command10_Click()
If b = "" Then Exit Sub
a = "+"
e = "+"
f = b
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command11_Click()
If b = "" Then Exit Sub
f = b
a = "-"
e = "-"
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command12_Click()
If b = "" Then Exit Sub
a = "*"
e = "*"
f = b
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command13_Click()
If b = "" Then Exit Sub
a = "/"
e = "/"
f = b '把操作數1提取出來
Text1.Text = ""
Text1.Text = Text1.Text a
End Sub
Private Sub Command16_Click()
'判斷有運算符就清零
If Text1.Text = "+" Or Text1.Text = "-" Or Text1.Text = "*" Or Text1.Text = "/" Then Text1.Text = ""
'判斷有零和空值就禁止輸入0
'發(fā)現運算結果就清零
If d "" Then Text1.Text = "": d = ""
If Text1.Text = "0" Then
Else
a = 0
If d "" Then Text1.Text = "": d = ""
Text1.Text = Text1.Text a
b = Text1.Text
End If
End Sub
簡單點的:
dim 上一個數 as double
dim 下一個數 as double
dim 結果 as double
dim 操作 as string
private sub 加減乘除(byval sender as object, byval e as eventargs) handles 加.click, 減.click, 乘.click, 除.click
上一個數 = cdbl(輸入框.text) ' 存儲當前輸入的數值
輸入框.text = "" ' 等待下一個數值
select case sender.text ' 根據按下的按鈕的文本屬性確定你要做什么,這里可以用加減乘除號代替
case "加"
操作 = "加"
case "減"
操作 = "減"
case "乘"
操作 = "乘"
case "除"
操作 = "除"
end select
end sub
private sub 計算(byval sender as object, byval e as eventargs) handles 等號.click
下一個數 = 輸入框.text
輸入框.text = ”“
select case 操作
case "加"
結果 = 上一個數 + 下一個數
case "減"
結果 = 上一個數 - 下一個數
case "乘"
結果 = 上一個數 * 下一個數
case "除"
結果 = 上一個數 / 下一個數
end select
輸入框.text = cstr(結果)
上一個數 = 結果
end sub
.NET 的哈,我沒有 .NET 現在,不知道行不行