Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asptoday_discuss thread: Hexadecimal arithmetic in ASP with VB script


Message #1 by "Sasi Vellolil" <sasiv@a...> on Thu, 21 Nov 2002 15:12:47
I having problem treating an array element as an hex number
Please see the code below:

<%
        sArray(17) 
	sCID = "322197AD7CC226D411B534DCE56B383CB4"

		nstrlen = Len(sCID)
		''''
		'' store sCID into an arry
		''''
	
		j = 1
		
		For i = 1 to (nstrlen/2)
		
			sArray(i) =  Mid(sCID,j, 2) 
			j = j + 2
		
		Next

                ''At this point
                '' sArray(1) will be 32
                '' sArray(2) will be 21
                ''  .....
                '' sArray(17) will be B4  

		''''
		''now calculate checksum
		''''
	
		csum = 1

		   For k = 1 to nstrlen/2
		   csum =  csum * (CLng(sArray(k))- 8 )
					
		Next

%>


My questions is about the following line: 	
		csum =  csum * (CLng(sArray(k))- 8 )

I want sArray(k) elements to be treate as hex instead of decimal

For example, when k = 1
csum = 1*(32-8) = 24 (this is what I am getting right now)


But I want 32 to be treated as an hexadecimal number (32h) so that
csum will be equal to 1*(32h-8) = 2Ah (This is what I want)

In cfm (cold fusion) you can easily do this by:
			csum =  csum * (InputBaseN((sArray(k),16))- 8 )


So how can we do this ASP with VBscript?

Any help will be greatly appreciated.


Message #2 by hiran kota <hiransatya@y...> on Fri, 22 Nov 2002 01:27:56 -0800 (PST)
hello,

   you can use hex(number) function which returns hexa
decimal value. I think, this may help you.

hiran.




--- Sasi Vellolil <sasiv@a...> wrote:
> I having problem treating an array element as an hex
> number
> Please see the code below:
> 
> <%
>         sArray(17) 
> 	sCID = "322197AD7CC226D411B534DCE56B383CB4"
> 
> 		nstrlen = Len(sCID)
> 		''''
> 		'' store sCID into an arry
> 		''''
> 	
> 		j = 1
> 		
> 		For i = 1 to (nstrlen/2)
> 		
> 			sArray(i) =  Mid(sCID,j, 2) 
> 			j = j + 2
> 		
> 		Next
> 
>                 ''At this point
>                 '' sArray(1) will be 32
>                 '' sArray(2) will be 21
>                 ''  .....
>                 '' sArray(17) will be B4  
> 
> 		''''
> 		''now calculate checksum
> 		''''
> 	
> 		csum = 1
> 
> 		   For k = 1 to nstrlen/2
> 		   csum =  csum * (CLng(sArray(k))- 8 )
> 					
> 		Next
> 
> %>
> 
> 
> My questions is about the following line: 	
> 		csum =  csum * (CLng(sArray(k))- 8 )
> 
> I want sArray(k) elements to be treate as hex
> instead of decimal
> 
> For example, when k = 1
> csum = 1*(32-8) = 24 (this is what I am getting
> right now)
> 
> 
> But I want 32 to be treated as an hexadecimal number
> (32h) so that
> csum will be equal to 1*(32h-8) = 2Ah (This is what
> I want)
> 
> In cfm (cold fusion) you can easily do this by:
> 			csum =  csum * (InputBaseN((sArray(k),16))- 8 )
> 
> 
> So how can we do this ASP with VBscript?
> 
> Any help will be greatly appreciated.
> 
> 
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus ? Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
Message #3 by Sasi Vellolil <sasiv@a...> on Fri, 22 Nov 2002 10:26:14 -0500
Hello Hiran,

I knew about hex() function.
But that is not what I want. My numbers are already in hex.
Problem is VBS treats them as decimal. So, again how
to specify the number system format in VB script?

Thanks for the reply anyway.
Sasi

> -----Original Message-----
> From:	hiran kota [SMTP:hiransatya@y...]
> Sent:	Friday, November 22, 2002 4:28 AM
> To:	ASPToday Discuss
> Subject:	[asptoday_discuss] Re: Hexadecimal arithmetic in ASP with VB
> script
> 
> hello,
> 
>    you can use hex(number) function which returns hexa
> decimal value. I think, this may help you.
> 
> hiran.
> 
> 
> 
> 
> --- Sasi Vellolil <sasiv@a...> wrote:
> > I having problem treating an array element as an hex
> > number
> > Please see the code below:
> > 
> > <%
> >         sArray(17) 
> > 	sCID = "322197AD7CC226D411B534DCE56B383CB4"
> > 
> > 		nstrlen = Len(sCID)
> > 		''''
> > 		'' store sCID into an arry
> > 		''''
> > 	
> > 		j = 1
> > 		
> > 		For i = 1 to (nstrlen/2)
> > 		
> > 			sArray(i) =  Mid(sCID,j, 2) 
> > 			j = j + 2
> > 		
> > 		Next
> > 
> >                 ''At this point
> >                 '' sArray(1) will be 32
> >                 '' sArray(2) will be 21
> >                 ''  .....
> >                 '' sArray(17) will be B4  
> > 
> > 		''''
> > 		''now calculate checksum
> > 		''''
> > 	
> > 		csum = 1
> > 
> > 		   For k = 1 to nstrlen/2
> > 		   csum =  csum * (CLng(sArray(k))- 8 )
> > 					
> > 		Next
> > 
> > %>
> > 
> > 
> > My questions is about the following line: 	
> > 		csum =  csum * (CLng(sArray(k))- 8 )
> > 
> > I want sArray(k) elements to be treate as hex
> > instead of decimal
> > 
> > For example, when k = 1
> > csum = 1*(32-8) = 24 (this is what I am getting
> > right now)
> > 
> > 
> > But I want 32 to be treated as an hexadecimal number
> > (32h) so that
> > csum will be equal to 1*(32h-8) = 2Ah (This is what
> > I want)
> > 
> > In cfm (cold fusion) you can easily do this by:
> > 			csum =  csum * (InputBaseN((sArray(k),16))- 8 )
> > 
> > 
> > So how can we do this ASP with VBscript?
> > 
> > Any help will be greatly appreciated.
> > 
> > 
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com

  Return to Index