Wrox Home  
Search P2P Archive for: Go

  Return to Index  

activex_data_objects thread: ASP and hexadecimal arithmetic


Message #1 by "Sasi Vellolil" <sasiv@a...> on Wed, 20 Nov 2002 02:59:52
        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 "Phil Griffiths" <pgtips@m...> on Thu, 21 Nov 2002 08:49:04
There is no built-in hex conversion function in VBS, but JScript has one 
called parseInt which allows you to specify the base, e.g. hexNumber = 
parseInt(hexString, 16).

BTW, this is an ADO list not an ASP list.

Phil
>-----------------------------------------
>.....
> 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.

> 

  Return to Index