Vb. NET converts decimal to 16 method (from Le Bo net)

Source: Internet
Author: User

Vb. NET converts the decimal system to a 16-way

' Use: Converts decimal to hexadecimal
' Input: Dec (decimal number)
' Input data type: Long
' Output: Dec_to_hex (hexadecimal number)
' Output data type: String
"The maximum number entered is 2147483647 and the maximum output is 7FFFFFFF.
Public Function Dec_to_hex (DEC as Long) as String
Dim A as String
Dec_to_hex = ""
Do While Dec > 0
A = CSTR (Dec Mod 16)
Select Case A
Case "Ten": A = "a"
Case "One": A = "B"
Case "a": A = "C"
Case "a": A = "D"
Case "a": A = "E"
Case "a": A = "F"
End Select
Dec_to_hex = A & Dec_to_hex
Dec = DEC/16
Loop
End Function

Vb. NET Self function:
Decimal octal: Oct (num)
Hexadecimal octal: Oct ("&h" & Num)
Decimal 16 binary: Hex (num)
Octal turn 16: Hex ("&o" & Num)

16 Convert to Decimal
Dim Str as String
str = Text2.text
Text10.text = CLng ("&h" & str)

decimal

The decimal digit notation includes the decimal and the bit value system two principles, "Ten" is full 10 into one; "Bit value" is the same number of digits in different positions represented by the number is different, such as three digits "111", The right of "1" in the single digit represents one, the middle of "1" on the 10-digit represents a 10, the left of the "1 "On the Hundred, it means a hundred. This makes the extremely difficult integer representation and calculus so simple and easy that people tend to overlook its crucial role in the development of mathematics.

Binary System

Binary system is widely used in computing technology. Binary data is a number represented by 0 and 12 digits. Its base is 2, the rounding rule is "every two enters one", the borrow rule is "borrows one when two". The binary data is also based on the position counting method, with the power of 2 as the base. For example, binary data 110.11, the order of the size of the 2^2, 2^1, 2^0, 2^-1, 2^-2. For n-bit integers, the binary data for M-decimal decimals is represented by a weighted coefficient expansion, which can be written as:

(a(n-1)a(n-2) ... a (m)) 2=a (n-1) x2^ (n-1) +a (n-2) x2^ (n-2) +......+a (1) x2^1+a (0) x2^0+a ( -1) x2^ ( -1) +a ( -2) x2^ ( -2) +......+a (m) x2^ (m)

Binary data can generally be written as: (A (n-1) a (n-2) ... a (1) a (0). A ( -1) a ( -2) ... a (m)) 2.

Note: ' More. NET source and example, from Le Bo network www.lob.cn

1. AJ represents the coefficient of J-bit, which is a number in 0 and 1.

2.a (n-1) (n-1) for subscript, input method can not be typed so enclose in parentheses, avoid confusion.

3.2^2 represents 2 squared, and so on.

hexadecimal

Hexadecimal is a representation of the data in the computer. It is different from the decimal notation in our daily life. It consists of 0-9,a-f. The corresponding relationship with the 10 binary is:

0-9 corresponds to 0-9;

A-f corresponds to 10-15;

The number of N-ary can be expressed in 0---(N-1) for more than 9 letters A-F

For example:

The 10-in-32 representation of the 16-in-system is: 20

The 16-in-32 representation of the 10-in-system is: 3x16^1+2x16^0=50

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.