求助!如何将超过10位的十进制转成二进制呀?
不管是将Decimalvalue改成long还是double,都会在数值大于2,147,483,647时溢出,这样就不能使十位以上十进制成功转成二进制了,小弟初涉VB,还望各位大哥指教啊!!!在这先谢过了!!!
代码如下:
Public Function DecimalToBinary(DecimalValue As Long, MinimumDigits As Integer) As String
Dim result As String
Dim ExtraDigitsNeeded As Integer
Dim temp_b As IntegerDecimalValue = Abs(DecimalValue)
Do
temp_b = DecimalValue Mod 2
result = CStr(temp_b) & result
DecimalValue = DecimalValue \ 2
Loop While DecimalValue > 0
ExtraDigitsNeeded = MinimumDigits - Len(result)
If ExtraDigitsNeeded > 0 Then
result = String(ExtraDigitsNeeded, "0") & result
End If
DecimalToBinary = result
End Function