# Read binary digits into memory

I previously (under a different name) how to read the binary digits from a file and write them to a ascii text file in either binary or hex, but now i am wondering if there is a way to read them into an integer in memory as a decimal number.
Asked:
###### Who is Participating?

Commented:
Use the following function to change base 2 to base 10

Dim iInt As Integer

iInt = Val(nTOm(Text5, 2, 10))

Private Function nTOm(sX As String, n As Integer, m As Integer)

'works for number bases 2 to 16

Dim lNumber As Long
Dim c As Integer
Dim sAtom As String
Dim lVal As Long
Dim x As Long

For c = Len(sX) To 1 Step -1

sAtom = UCase(Mid(sX, c, 1))

If n > 10 Then

If sAtom >= "A" And sAtom <= "F" Then

lVal = Asc(sAtom) - Asc("A") + 10

Else

lVal = CLng(sAtom)

End If

Else

lVal = CLng(sAtom)

End If

lNumber = lNumber + lVal * n ^ x

x = x + 1

Next

nTOm = ""

While lNumber > 0

x = lNumber Mod m

If x < 10 Then

sAtom = CStr(x)

Else

sAtom = Chr(Asc("A") + x - 10)

End If

nTOm = sAtom + nTOm

lNumber = lNumber \ m

Wend

If nTOm = "" Then nTOm = "0"

End Function

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Already a member? Login.

All Courses

From novice to tech pro — start learning today.