Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integer to bit string

Status
Not open for further replies.

slackerJr

Programmer
Jul 10, 2006
4
0
0
SE
Hi!

I need to convert an integer to a bit string with classic asp. Any hints on how to do this?

Thanks.
 
Like this.
[tt]
sub cvt(ninteger,bitstring)
'convert integer to bit string (no padding)
'bitstring is out-param
dim dvd
bitstring=cstr(ninteger mod 2) & bitstring
dvd=n\2
if dvd<>0 then
cvt dvd,bitstring
end if
end sub

dim n,bitstr
n=8
bitstr=""
cvt n,bitstr
response.write n & " : " & bitstr & "<br />"
[/tt]
 
Correcting a typo (a change of mind on naming during draft up). A re-take.
[tt]
sub cvt(ninteger,bitstring)
'convert integer to bit string (no padding)
'bitstring is out-param
dim dvd
bitstring=cstr(ninteger mod 2) & bitstring
dvd=n[red]integer[/red]\2
if dvd<>0 then
cvt dvd,bitstring
end if
end sub
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top