VB將十六制數(shù)轉(zhuǎn)換成二進制數(shù)需要編寫自定義函數(shù)解決。
創(chuàng)新互聯(lián)服務(wù)項目包括鳳陽網(wǎng)站建設(shè)、鳳陽網(wǎng)站制作、鳳陽網(wǎng)頁制作以及鳳陽網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,鳳陽網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到鳳陽省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
Option Explicit
Dim sBin
Dim sHex
Dim sHex1
Dim BinData
Const s1 = "0000101001101111000", s2 = "0125A4936DB7FEC8"
Dim yTemp() As Byte
Public Function HexToBin(ByVal sHex As String) As String
Dim i As Integer, sBin As String
sHex = UCase(sHex)
For i = 1 To Len(sHex)
sBin = sBin Mid(s1, InStr(1, s2, Mid(sHex, i, 1)), 4)
Next i
HexToBin = sBin
BinData = sBin
End Function
Private Sub Command1_Click()
sHex = Text1
Call HexToBin(sHex)
Text2 = BinData
End Sub
為了表示對你的尊重,我就先不寫代碼了.
主要有3種思路
1、通用的,把
16進制
字符串轉(zhuǎn)換成對應(yīng)的進制表示(譬如先用val()轉(zhuǎn)成整形,然后再換進制,換進制的算法你會吧?),然后用mid截取需要的段。
2、只適用于問題1。直接用iif(val(s)
and
2^(i-1),1,0)
3、適用于2與16進制之間的轉(zhuǎn)換:記住4位
2進制數(shù)
對應(yīng)1位16進制數(shù),具體算法自己想咯
==================================
1、er...首先請教hen是有什么功能的函數(shù)?
2、關(guān)于負(fù)數(shù):當(dāng)最高位(bit)為1時,用
10進制
表示就是負(fù)數(shù).你可以注意不要讓最高位為1,或者用long型,或者用currency,或者自己寫一個類。
3、速度的話我覺得不會太慢吧,就算你有10m的數(shù)據(jù)也至多不過幾秒?未必要另外建立一個數(shù)組,這要看你的需求。非要用數(shù)組的話,注意不要用redim。你想要速度的話,可以用第2種方法?;蛘吒囊幌?,由于4位2進制對1位16進制,只要抽出16進制中需要判斷的那一位加以處理就好了。更發(fā)燒一點的話,不要用val,自己寫一個有針對性的;iif也不要用,用if代替;
乘方
什么的都用加減代替;實在不夠快寫匯編。
Function siliuTo2(ByVal su As String) As String
'16進制轉(zhuǎn)換為2進制
For i = 1 To Len(su)
n = Mid(su, i, 1)
Select Case n
Case 0
siliuTo2 = siliuTo2 "0000"
Case 1
siliuTo2 = siliuTo2 "0001"
Case 2
siliuTo2 = siliuTo2 "0010"
Case 3
siliuTo2 = siliuTo2 "0011"
Case 4
siliuTo2 = siliuTo2 "0100"
Case 5
siliuTo2 = siliuTo2 "0101"
Case 6
siliuTo2 = siliuTo2 "0110"
Case 7
siliuTo2 = siliuTo2 "0111"
Case 8
siliuTo2 = siliuTo2 "1000"
Case 9
siliuTo2 = siliuTo2 "1001"
Case "A"
siliuTo2 = siliuTo2 "1010"
Case "B"
siliuTo2 = siliuTo2 "1011"
Case "C"
siliuTo2 = siliuTo2 "1100"
Case "D"
siliuTo2 = siliuTo2 "1101"
Case "E"
siliuTo2 = siliuTo2 "1110"
Case "F"
siliuTo2 = siliuTo2 "1111"
Case Else
siliuTo2 = "數(shù)據(jù)錯誤!"
Exit Function
End Select
Next
siliuTo2 = Format(siliuTo2, "0") '去除前面的0
End Function
首先引入System.IO命名空間
Imports System.IO
然后使用文件流來讀入數(shù)組:
Dim bytes() As Byte
Using fs As New FileStream(文件路徑,FileMode.Open)
ReDim bytes(fs.Length-1)
fs.Read(bytes,0,fs.Length)
fs.Close()
End Using
這樣bytes就是整個文件的所有字節(jié)了
從字節(jié)生成Image:
Dim img As Image = Image.FromStream(New MemoryStream(bytes))
img就是圖片了
Option Explicit
Dim Jz As Integer, K As Boolean
Private Sub Command1_Click()
Pic.Cls
If K Then Jz = Val(Qtjz.Text)
If Pd(Text1.Text, Jz) Then Pic.Print "選擇的進制與數(shù)不符": Exit Sub
If Jz = 0 Then Pic.Print "請先輸入進制" Else Pic.Print Zh(Text1.Text, Jz)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub Option1_Click(Index As Integer)
K = False
Select Case Index
Case 0
Jz = 2
Case 1
Jz = 8
Case 2
Jz = 10
Case 3
Jz = 16
Case 4
K = True
Qtjz.Text = ""
Qtjz.SetFocus
End Select
If Index 4 Then Command1.SetFocus
End Sub
Private Sub Qtjz_Click()
Qtjz.Text = ""
End Sub
Private Sub Text1_Click()
Text1.Text = ""
End Sub
Private Function Zh(a As String, b As Integer) As Integer
Dim c As String, i, d As Integer
a = LCase(a)
For i = 1 To Len(a)
c = Mid(a, Len(a) + 1 - i, 1)
If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)
Zh = Zh + d * b ^ (i - 1)
Next i
End Function
Private Function Pd(a As String, b As Integer) As Boolean
Dim c As String, i, d As Integer
Pd = False
For i = 1 To Len(a)
c = Mid(a, Len(a) + 1 - i, 1)
If Asc(c) 96 Then d = Asc(c) - 87 Else d = Val(c)
If d b - 1 Then Pd = True: Exit Function
Next i
End Function