Is there any function in asp that can convert inte

# Thread: Is there any function in asp that can convert inte

1. tat
Junior Member
Join Date
Dec 1969
Posts
27

## Is there any function in asp that can convert inte

I need to convert integer to binary and get a value of particular bit. Any idea how to do it?

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

## Don't need a function

&#060;%<BR>bit = &h0040<BR>num = 718123<BR><BR>If (num AND bit) &#060;&#062; 0 Then<BR> Response.Write "The bit is set"<BR>End If<BR>%&#062;<BR><BR>AND and OR can be used as binary operators if both operands are integers or longs.<BR><BR>

3. tat
Junior Member
Join Date
Dec 1969
Posts
27

## binary operators

I guess I don&#039;t understand a concept of it. For example I have an integer 131841 (4 bytes). How can I find out if 16th bit is 1 or 0?

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

## You have to know...

...what the hex form for the "16th bit" is.<BR><BR>You could do it with math, but the best way is probably to build an array:<BR><BR>&#060;%<BR>bits = Array( &h0001, &h0002, &h0004, &h0008, &h0010, &h0020, &h0040, &h0080, _<BR> &h0100, &h0200, &h0400, &h0800, &h1000, &h2000, &h4000, &h8000, _<BR> &h00010000, &h00020000, ... etc. ... )<BR>%&#062;<BR><BR>And then you can use<BR> bits(bitnum)<BR>to get the value for that bit. So you would just do:<BR> If ( 131841 AND bits(16) ) &#060;&#062; 0 Then ...<BR><BR>

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

## Instead of making the array...

...a bunch of constants, you could build it easily:<BR><BR>&#060;%<BR>Dim bits(31)<BR>n = 1<BR>For b = 0 To 31<BR> bits(b) = CLNG(n)<BR> n = n + n<BR>Next<BR>%&#062;<BR><BR>If that chokes when b is 31 (I think it will), then just do the loop from 0 to 30 and put <BR> bits(31) = &h80000000<BR>separately.<BR><BR>

6. tat
Junior Member
Join Date
Dec 1969
Posts
27

## Thank you Bill!

Thank you Bill!

#### Posting Permissions

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