How to Convert a Decimal Number to a Binary Number in a StringLast reviewed: June 21, 1995Article ID: Q109260 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
SUMMARYThe following sample program shows how to convert a decimal number into its equivalent binary representation stored in a string. This program accepts a nine-digit positive decimal number and returns a 32- character string that represents the number in binary notation. Negative numbers are converted into the 32-digit, twos-complement binary format used by long integers in Basic.
MORE INFORMATIONIn decimal numbers (base-ten numbers), every decimal place is a power of 10. Decimal digits can have values from zero to nine. In binary numbers (base-two numbers), every decimal place is a power of two. Binary digits can only have values of 0 or 1.
Sample Program
Decimal Value Binary Value 0 00000000000000000000000000000000 21 00000000000000000000000000010101 1024 00000000000000000000010000000000 32767 00000000000000000111111111111111 32768 00000000000000001000000000000000 65536 00000000000000010000000000000000 16777216 00000001000000000000000000000000 999999999 00111011100110101100100111111111 -1 11111111111111111111111111111111 -3 11111111111111111111111111111101 |
Additional reference words: 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |