# convert a decimal value to binary

### Question

• Hi,
How can I convert a decimal value to binary and then assign each bit of the word to it's own image that will represent a hi/low state? The images on the form will change their background color which will lighten or darken depending on their hi/low state.
Ken
Sunday, February 04, 2007 12:48 AM

To convert a number to its binary representation you can use the convert class..

Dim L As Long = 11

Dim x As String = Convert.ToString(L, 2)

Debug.Print(x) '1011

However to convert a Decimal number you will have to create your own algorithm

Sunday, February 04, 2007 1:54 AM
• Dim BinaryString As String = "10010111"

Dim SecondLSB As String = BinaryString.Substring(BinaryString.Length - 2, 1)

Sunday, February 04, 2007 3:19 AM

### All replies

To convert a number to its binary representation you can use the convert class..

Dim L As Long = 11

Dim x As String = Convert.ToString(L, 2)

Debug.Print(x) '1011

However to convert a Decimal number you will have to create your own algorithm

Sunday, February 04, 2007 1:54 AM
•

"To convert a number to its binary representation you can use the convert class.."

Dman,

Thank you for maintaining distinctions that are important for computer scientists to communicate with each each. I think the people who are in a position to teach have an obligation to do that.

I appreciate it that you say "code" instead of scripts. I appreciate it that you recognize and maintain needed distinctions.

Sunday, February 04, 2007 2:48 AM
• Thank you Dman.

After converting a number to its binary representation how can I grab an individual bit, lets say the second LSB bit of 10010111.

Ken

Sunday, February 04, 2007 3:14 AM
• Dim BinaryString As String = "10010111"

Dim SecondLSB As String = BinaryString.Substring(BinaryString.Length - 2, 1)

Sunday, February 04, 2007 3:19 AM