Decimal to Binary Conversion

# Thread: Decimal to Binary Conversion

1. Senior Member
Join Date
Dec 1969
Posts
220

## Decimal to Binary Conversion

Is there a function to convert a number to binary format such as the hexadecimal conversion?<BR><BR>For instance: hex(16) = 10<BR>But there&#039;s no: bin(16) = 10000<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## None built in, but not hard

&#060;HTML&#062;&#060;BODY&#062;<BR>&#060;%<BR>Fun ction Bin(num)<BR> num = CLng(num) &#039; only integers allowed<BR> Dim s<BR> s = ""<BR> Do <BR> If (num AND 1) &#060;&#062; 0 Then s = "1" & s Else s = "0" & s <BR> num = num 2<BR> Loop Until num = 0<BR> Bin = s<BR>End Function<BR>%&#062;<BR>A couple of tests:&#060;HR&#062;<BR>Bin(17) = &#060;%= Bin(17) %&#062;&#060;HR&#062;<BR>Bin(177) = &#060;%= Bin(177) %&#062;&#060;HR&#062;<BR><BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
220

## RE: None built in, but not hard

Thanks. I did something similar to that. I just wasn&#039;t sure if there was a command that would make it a lot shorter.<BR><BR>Thanks.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•