vb编程十进制转换为二进制
VB编程使16进制转换为2进制?
VB编程使16进制转换为2进制?
vb编程,用do-while循环实现十进制转二进制和十六进制:
1、十进制转为二进制:
Sub DecimalToBinary()Dim intNumber As IntegerDim intRemainder As IntegerDim strRemainder As StringDim strBinaryNumber As StringintNumber CInt(InputBox(Enter number in decimal:, DECIMAL TO BINARY CONVERSION)
)Do While intNumber 1 intRemainder intNumber Mod 2 strRemainder CStr(intRemainder) intNumber intNumber 2 strBinaryNumber strRemainder strBinaryNumberLoopMsgBox The Number in Binary is : strBinaryNumber, , DECIMAL TO BINARY CONVERSIONEnd Sub2、十进制转十六进制:
Sub DecimalToHexadecimal() Dim intNumber As Integer Dim intRemainder As Integer Dim strRemainder As String Dim strHexaNumber As String intNumber CInt(InputBox(Enter number in decimal:, DECIMAL TO HEXADECIMAL CONVERSION)
) Do While intNumber 1 intRemainder intNumber Mod 16 strRemainder CStr(intRemainder) intNumber intNumber 16 Select Case strRemainder Case 10: strRemainder A Case 11: strRemainder B Case 12: strRemainder C Case 13: strRemainder D Case 14: strRemainder E Case 15: strRemainder F End Select strHexaNumber strRemainder strHexaNumber Loop MsgBox The Number in Hexadecimal is : strHexaNumber, , DECIMAL TO HEXADECIMAL CONVERSIONEnd Sub
vb中怎么将一个十进制数转化为二进制数字呢?
朋友怕不是没有上过小学奥数
例如在二进制中,个位代表的就是2的0次,十位就代表的是2的一次。以此类推,从右向左数,第n位就是2的n-1次幂。同理的,对于一个m进制下的数,第n为代表的就是m的n-1次幂。
对于二进制向10进制转换,每一位的数值乘以它对应的大小,并进行累加,即可得到相应的10进位数。
对于10进制向2进制的转换,第1步先对一个十进制数b(0)÷2,得到第1位整数b1和余数c1。
第2步,用得到的b1除以2,记下新的整数b2和余数c2,直到b0。
第3步,将所得到的c,从最后一部写到第1部。顺序即为:……c2c1