VB中二進製 八進製 十進製 十六進製的符號怎麼表示
二進製 Binary
八進製 octal
十進製 decimal
十六進製 hexadecimal
單詞 第一個 字母 就可以了!
嗬嗬
VB中的八進製怎麼算
Oct 函數
返回 Variant (String),代表一數值的八進製值。
語法
Oct(number)
必要的 number 參數為任何有效的數值表達式或字符串表達式。
說明
如果 number 尚非整數,那麼在執行前會先四舍五入成最接近的整數。
如果 number 為 Oct 返回
Null Null
Empty 零 (0)
任何其他的數字 最多可到 11 個八進製字符。
可以將適當範圍的數前綴以 &O 來直接表示八進製數字。例如,八進製表示法的 &O10 代表十進製的 8。
Oct 函數示例
本示例使用 Oct 函數將某數值轉換為 8 進製表達式。
Dim MyOct
MyOct = Oct(4) ' 返回 4。
MyOct = Oct(8) ' 返回 10。
MyOct = Oct(459) ' 返回 713。
vb中怎麼編寫判斷一個數是不是八進製數
請參考
Private Sub Command1_Click()
Text2 = ReadOctal(Text1)
End Sub
Private Sub Command2_Click()
Text1 = WriteOctal(Text2)
End Sub
Function ReadOctal(num As String)
For i = 1 To Len(num)
s = Val(Mid(num, i, 1))
If s > 7 Then MsgBox "八進製數中不能有大於7的數字!": Exit Function
ReadOctal = ReadOctal * 8 + s
Next
End Function
Function WriteOctal(num As String)
Dim a%(10), m%, i%
s = ""
m = num
i = 0
Do While m <> 0
a(i) = m Mod 2
m = m \ 2
i = i + 1
Loop
For k = i - 1 To 0 Step -1
s = s & a(k)
Next
i = Len(s) Mod 3
Select Case i
Case 1: s = "00" & s
Case 2: s = "0" & s
End Select
For i = 1 To Len(s) Step 3
s1 = Mid(s, i, 3)
s2 = 0
For j = 1 To 3
s2 = s2 * 2 + Val(Mid(s1, j, 1))
Next
WriteOctal = WriteOctal & s2
Next
End Function
求 vb 八進製轉化為二進製的代碼
用途:將八進製轉化為二進製
輸入:Oct(八進製數)
輸入數據類型:String
輸出:OCT_to_BIN(二進製數)
輸出數據類型:String
輸入的最大數為2147483647個字符
Public OCT_to_BIN(ByVal Oct As String) As String
Dim i As Long
Dim B As String
For i = 1 To Len(Oct)
Select Case Mid(Oct, i, 1)
Case "0": B = B & "000"
Case "1": B = B & "001"
Case "2": B = B & "010"
Case "3": B = B & "011"
Case "4": B = B & "100"
Case "5": B = B & "101"
Case "6": B = B & "110"
Case "7": B = B & "111"
End Select
Next i
While Left(B, 1) = "0"
B = Right(B, Len(B) - 1)
Wend
OCT_to_BIN = B
End
十進製轉化為八進製的vb代碼
代碼: Private Sub Command1_Click()
Dim x As Long
x = Val(InputBox("請輸入一個十進製數:"))
Print "轉換為八進製的結果是: ", Str(DEC_to_OCT(x))
End Sub
Public Function DEC_to_OCT(Dec As Long) As String
DEC_to_OCT = ""
Do While Dec > 0
DEC_to_OCT = Dec Mod 8 & DEC_to_OCT
Dec = Dec \ 8
Loop
End Function 圖:
VB編程,輸入一個八進製數,轉換成為十進製數的子過程。
Private Sub Form_Click()
Dim N As String, S As Double
N = InputBox("請輸入一個8進製數")
For i = Len(N) To 1 Step -1
S = S + 8 ^ Val(Len(N) - i) * Val(Mid(N, i, 1))
Next
Print S
End Sub
VB高手用VB編寫八進製和十進製數
Private?Sub?Command1_Click()
Text2?=?ReadOctal(Text1)
End?Sub
Private?Sub?Command2_Click()
Text1?=?WriteOctal(Text2)
End?Sub
Function?ReadOctal(num?As?String)
For?i?=?1?To?Len(num)
s?=?Val(Mid(num,?i,?1))
If?s?>?7?Then?MsgBox?"八進製數中不能有大於7的數字!":?Exit?Function
ReadOctal?=?ReadOctal?*?8?+?s
Next
End?Function
Function?WriteOctal(num?As?String)
Dim?a%(10),?m%,?i%
s?=?""
m?=?num
i?=?0
Do?While?m?<>?0
a(i)?=?m?Mod?2
m?=?m?\?2
i?=?i?+?1
Loop
For?k?=?i?-?1?To?0?Step?-1
s?=?s?&?a(k)
Next
i?=?Len(s)?Mod?3
Select?Case?i
Case?1:?s?=?"00"?&?s
Case?2:?s?=?"0"?&?s
End?Select
For?i?=?1?To?Len(s)?Step?3
s1?=?Mid(s,?i,?3)
s2?=?0
For?j?=?1?To?3
s2?=?s2?*?2?+?Val(Mid(s1,?j,?1))
Next
WriteOctal?=?WriteOctal?&?s2
Next
End?Function
請采納
VB編程十進製轉八進製,具體怎麼寫,作業快交了,急
Private Sub Form_Click()
Dim N As String, S As Double
N = InputBox("請輸入一個8進製數")
For i = Len(N) To 1 Step -1
S = S + 8 ^ Val(Len(N) - i) * Val(Mid(N, i, 1))
Next
Print S
End Sub
麻煩幫忙用VB做一個十進製轉換為二進製,八進製,十六進製的程序。圖片如下
...........................可以幫你。
VB中八進製轉換十進製
第一種:如果知道所轉換的十進製值的類型的的直接使用CBool, CByte, CCur, CDate, CDbl, CDec, CInt, CLng, CSng, CStr, CVar, CVErr等強製轉化類型比如
把八進製的11轉化為十進製的integer類型的話是字節長度為16的9
轉發方法是debug.print cint(“&011”)
你將會在調試窗口中看到9明白沒?
第二種:笨辦法,例如八進製abcd轉換十進製是
a*8^3+b*8^2+c*8+d
轉載請注明出處句子大全網 » VB中二進製八進製十進製十六進製的符