Decimal to Binary and Vice-Versa in VB6

I have some data that is unfortunately returned by a DLL that i call only in decimal, hexa, or string format.
I need to process it in the basic binary format.
So, i need the basic binary like 10110010 .
How do I convert it from dec to bin and vice-versa in Visual Basic 6? I didn't find a function for that in MSDN.

Further details:
I a writing a program that would like to be a software oscilloscope for a custom-made data aquisition card. This card is connected to the parallel port(LPT) and I am accessing it from Windows NT through the DriverLINX Port I/O Driver for Win95 and WinNT DLL from
When reading a certain address from the LPT, a dec, hex, or string of these is returned. And I need the bin to see if a certain pin from the LPT is 0 or 1(high, or low)

Thank you very much.
Who is Participating?
rspahitzConnect With a Mentor Commented:
Although the answer you seek may be in the above comments, this will only apply if the binary number is coming in as a string.

Based on your question, I'm wondering if those numbers are actually coming in a numbers, in which case binary number is only binary because that's how you interpret it; the same in hexadecimal.

For example, the number 10 is really the concept of this many things: ||||| |||||
You can interpret it as 1 group of ten things, two groups of 5 things or five groups of two things, etc.

You can also represent it as "A" things in hexadecimal or "1010" things in binary.

Internally, the computer stores everything in binary; VB merely interprets it according to a few allowable representations.

Therefore, in the computer, the only difference between a binary number, hexadecimal number, and decimal number is in how they are displayed.  When a dll wants a number, it doesn't care about the display; only the internal value.

When you say, "When reading a certain address from the LPT, a bin, hex, or string is returned" does that mean that the tool is returning a string of binary digits or a string of hex digits, or a string of something else?  If it's returning numbers, then a binary number and a decimal number are really the same thing.

>I need the bin to see if a certain pin from the LPT is 0 or 1(high, or low)

You can do this with a decimal number since it's really the same number:

(DecNum AND 1) returns 0 or 1 for the 0th bit (from the right)
(DecNum AND 2) returns 0 or 2 for the 1st bit
(DecNum AND 4) returns 0 or 4 for the 2nd bit
(DecNum AND 8) returns 0 or 8 for the 3rd bit
(DecNum AND 16) returns 0 or 16 for the 4th bit
(DecNum AND 32) returns 0 or 32 for the 5th bit
(DecNum AND 64) returns 0 or 64 for the 6th bit
(DecNum AND 128) returns 0 or 128 for the 7th bit

(If DecNum is 10)
debug.print DecNum AND 1 ' returns 0
debug.print DecNum AND 2 ' returns 2
debug.print DecNum AND 4 ' returns 0
debug.print DecNum AND 8 ' returns 8
decimal to binary:

A quick and easy function to return the binary value for a number, without any preceding "0"s. This function returns a string with the binary number.


click on the "Base Conversion" link

sorry, disregard everything above "checkout:" in the above comment
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Richie_SimonettiIT OperationsCommented:
Richie_SimonettiIT OperationsCommented:
Check this:
Function Pow(nNumber As Integer, ipower As Integer) As Integer
    Pow = nNumber ^ ipower
End Function
Private Sub Command1_Click()
Dim llen As Integer, idx As Integer, iPow As Integer
Dim iCount As Integer
llen = Len(Text1.Text)
For idx = llen To 1 Step -1
    iPow = iPow + (Mid$(Text1.Text, idx, 1) * Pow(2, iCount))
    iCount = iCount + 1
Next idx
MsgBox iPow
End Sub
Richie_SimonettiIT OperationsCommented:
Sorry, that was for binary to decimal.
Richie_SimonettiIT OperationsCommented:
That code was developed based on:
Richie_SimonettiIT OperationsCommented:
robertutAuthor Commented:
Thank you for your quick responses.
When I came back and saw the responses, I also read my question, adn discovered that I mistakenly wrote:

"When reading a certain address from the LPT, a BIN, hex, or string is returned" and "I have some data that is unfortunately returned by a DLL that i call only in BINARY, hexa, or string format." while what I really meant was:
"When reading a certain address from the LPT, a DEC, hex, or string is returned" and "I have some data that is unfortunately returned by a DLL that i call only in DECIMAL, hexa, or string format."

Anyway, still good answers came. Thak you.

for rspahitz:
the tool returns a value, not a string of deciaml digits, nor a string of hex digits, nor a string  of something else. It is my option to choose what I want it to return: Decimal, Hexa or a String of these.
Since I needed the binary value, I asked if maybe I could covert any of the above in binaries.
I need to test the presence of a low and immediately changing to high on a pin of the LPT in one part of the program; but later on I need the binary values.
I am designing this program for the old type of LPT, which is not bi-directional, that means that it cannot read 8 bits simultaneously. Thus my hardware has a multiplexor that allows to split the 8-bit number retuned by the A/D convertor in two 4-bit numbers sent in sequentially. Later I have to re-create the 8 bit from these two 4 bits(this will be a whole other question), convert it to long and display it on the chart.
Thank you.
So it sounds like my example above should help against each of the two 4-bit numbers.
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.

All Courses

From novice to tech pro — start learning today.