1. Hệ nhị phân là gì?
Hệ nhị phân (hay hệ đếm cơ số hai) là một hệ đếm dùng hai ký tự để biểu đạt một giá trị số, bằng tổng số các lũy thừa của 2. Như vậy, hệ nhị phân (tiếng Anh gọi là binary) là hệ đếm chỉ dùng 2 chữ số thay vì 10 chữ số như hệ thập phân, và 2 chữ số này thường là 0 và 1. Chính cái tên của nó cũng nói lên điều này: “nhị” tức là 2, “thập” tức là 10.2. Hệ thập phân là gì?
Hệ thập phân (hệ đếm cơ số 10) là hệ đếm dùng số 10 làm cơ số. Đây là hệ đếm được sử dụng rộng rãi nhất trong các nền văn minh thời hiện đại.3. Hệ thập lục phân là gì?
Hệ thập lục phân (hay hệ đếm cơ số 16, tiếng Anh: hexadecimal), hoặc chỉ đơn thuần gọi là thập lục, là một hệ đếm có 16 ký tự, từ 0 đến 9 và A đến F (chữ hoa và chữ thường như nhau). Hệ thống thập lục phân hiện dùng, được công ty IBM giới thiệu với thế giới điện toán vào năm 1963. Một phiên bản cũ của hệ thống này, dùng các con số từ 0 đến 9, và các con chữ A đến F, đã được sử dụng trong máy tính Bendix G-15, ra mắt năm 1956.Source code convert bin, dec, hex VB.NET:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Strconvert As String = TextBox1.Text
Dim Decimals As Integer
Dim hexadecimal As String
Dim Binary As String
Dim x As Integer
' convert Binary to Binary
If ComboBox1.Text = "Binary" And ComboBox2.Text = "Binary" Then
TextBox2.Text = TextBox1.Text
' convert Binary to Decimal
ElseIf ComboBox1.Text = "Binary" And ComboBox2.Text = "Decimal"
Decimals = Convert.ToInt32(Strconvert, 2)
TextBox2.Text = Decimals.ToString
' convert Binary to Hexadecimal
ElseIf ComboBox1.Text = "Binary" And ComboBox2.Text = "Hexadecimal"
Decimals = Convert.ToInt32(Strconvert, 2)
hexadecimal = Convert.ToString(Decimals, 16)
TextBox2.Text = hexadecimal
' convert Decimal to Binary
ElseIf ComboBox1.Text = "Decimal" And ComboBox2.Text = "Binary"
x = Convert.ToInt32(Strconvert)
Binary = Convert.ToString(x, 2)
TextBox2.Text = Binary
' convert Decimal to Hexadecimal
ElseIf ComboBox1.Text = "Decimal" And ComboBox2.Text = "Hexadecimal"
x = Convert.ToInt32(Strconvert)
hexadecimal = Convert.ToString(x, 16)
TextBox2.Text = hexadecimal
' convert Hexadecimal to Binary
ElseIf ComboBox1.Text = "Hexadecimal" And ComboBox2.Text = "Binary"
Decimals = Convert.ToInt32(Strconvert, 16)
Binary = Convert.ToString(Decimals, 2)
TextBox2.Text = Binary
' convert Hexadecimal to Decimal
ElseIf ComboBox1.Text = "Hexadecimal" And ComboBox2.Text = "Decimal"
Decimals = Convert.ToInt32(Strconvert, 16)
TextBox2.Text = Decimals.ToString
Else
If ComboBox1.Text = "Select Format" Or ComboBox2.Text = "Select Format" Or ComboBox1.Text = "" Or ComboBox2.Text = "" Then
MsgBox("Please Insert Select type to convert")
End If
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Add items into ComboBox1
ComboBox1.Items.Add("Binary")
ComboBox1.Items.Add("Decimal")
ComboBox1.Items.Add("Hexadecimal")
' Add items into ComboBox1
ComboBox2.Items.Add("Binary")
ComboBox2.Items.Add("Decimal")
ComboBox2.Items.Add("Hexadecimal")
' Add Text into ComboBox1
ComboBox1.Text = "Select Format"
' Add Text into ComboBox1
ComboBox2.Text = "Select Format"
End Sub
End Class
Chúc các bạn thành công với thủ thuật trên và tuỳ biến để sữ dụng cho mục đích cá nhân thật tốt nhé.
Theo LapTrinhVB
![[VB] Instructions for converting between binary (Bin), decimal (Dec) and hexadecimal (Hex) numbers [VB] Instructions for converting between binary (Bin), decimal (Dec) and hexadecimal (Hex) numbers](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL2_eDvNkcE7zsmdgJMMfbUPFb0r56XyqzJFgoRfVjpdpBBPmiBuCei-sfaQPpKWcThwqXShiqM41x2Sf3b9OsdloS7mSn6dzqEjCrPmAD3TnPoyxZt0r_947zqYZEww4RZJOwaFrYkaYaroiHolOnidOQK5I4vE5wD0ivgoqXiGkY8MRQK2J7JcVMUgg/s16000/%5BVB.NET%5D%20H%C6%B0%E1%BB%9Bng%20d%E1%BA%ABn%20chuy%E1%BB%83n%20%C4%91%E1%BB%95i%20qua%20l%E1%BA%A1i%20c%C3%A1c%20h%E1%BB%87%20s%E1%BB%91%20nh%E1%BB%8B%20ph%C3%A2n%20(Bin),%20th%E1%BA%ADp%20ph%C3%A2n%20(Dec)%20v%C3%A0%20th%E1%BA%ADp%20l%E1%BB%A5c%20ph%C3%A2n%20(Hex).png)

Comments