how do you convert Enormus numbers to HEX?

# Thread: how do you convert Enormus numbers to HEX?

1. Scott S Guest

## how do you convert Enormus numbers to HEX?

I am trying to write a function that will take 2 strings & hash them together. Basically i take the ascii value of each letter of each string & mash them together to form a large number. <BR><BR>for example, WITTMAN would come out to 78657784847387. I tried calling the HEX() function but i keep getting OVERFLOW errors, is there any way around this? or is there an easier way to hash 2 strings together? <BR><BR>

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

## RE: how do you convert Enormus numbers to HEX?

&#062;I am trying to write a function that will take 2 strings & hash &#062;them together. Basically i take the ascii value of each letter &#062;of each string & mash them together to form a large number. <BR>&#062;<BR>&#062;for example, WITTMAN would come out to 78657784847387. I tried &#062;calling the HEX() function but i keep getting OVERFLOW errors, &#062;is there any way around this? or is there an easier way to hash &#062;2 strings together? <BR><BR>In other words, you would want code that would convert 78657784847387 to Hex? <BR><BR>Do you realize that 78657784847387 is larger than the largest<BR>possible integer? (Which is 2,147,483,647.) So what VBScript<BR>does is automatically start using floating point numbers.<BR><BR>Do you realize that floating point numbers have an intrinsic<BR>accuracy limitation of about 15 digits? So that number<BR>you are using as your example is about as large as you can get<BR>and still guarantee accuracy. If I used "WITTMANXX", I assume<BR>that your algorithm would get an answer of something like<BR>78187712158153791712. Except that the computer is only capable<BR>of rendering that as approximately 781877121581538E+05 as a<BR>floating point number. (Oops...can&#039t even get the last <BR>displayable digit right. Darn. But right!)<BR><BR>So I *could* show you how to convert 78657784847387 into Hex,<BR>but I strongly suspect that your algorithm is faulty in the<BR>first place. You need to go back and learn the basic limitations<BR>of numeric processing on computers and, for efficiency, derive<BR>an algorithm that never exceeds 31 bits of accuracy (I&#039d say<BR>32 bits, but VBScript doesn&#039t understand unsigned numbers).<BR>There are many, many such algorithms published in many, many<BR>Computer Science textbooks, and surely there are places on the<BR>Web that display them, as well.<BR><BR>If you have some way of guaranteeing that you will never<BR>exceed 14 digits, then ask again and I&#039ll show you the way.<BR><BR><BR><BR>

3. Scott S Guest

## RE: how do you convert Enormus numbers to HEX?

When i originally posted this i was trying to develop a 2 way hash i wanted to be able to get back to the original data after it had been converted. after i thought about it some more i realized that a one way hash would work just as well, instead of going back to the original data i could just compare the hashed values (very similar to the way passwords are stored) so i changed the algorithm to reflect this new (well new to me) thinking. now instead of taking appending the ascii value of one letter to another, 2359 would be 2 letters for example, i simply add them & get 82, which keeps the numbers much much smaller & are easily converted to hex that way. also its probably going to be a bit faster in the end as i dont have to worry about derving any original values, just compare hashed ones. Thank you for your help, you were correct I was definitely headed down the wrong path. <BR><BR>Here are the functions I am using to complete the hash,<BR>as a side note Is there any way to get back to your original values once you hash them? I realize that it would be hard, i&#039m just wondering if its possible?<BR><BR>just a thought?<BR>-----------------------------------<BR>Function Convert(ByVal Str)<BR><BR> dim iPos <BR> iPos = 1<BR> While iPos &#060;= Len(Str)<BR> tmpVal = ASC(UCase(Mid(Str,iPos,1)))<BR> &#039NumVal = cstr(tmpVal) <BR> iPos = iPos + 1<BR> tmp2 = tmpVal + tmp2<BR> Wend<BR> Convert = clng(tmp2) <BR><BR>End Function<BR><BR>Function hash(ByVal FirstWord, ByVal Secondword)<BR><BR> dim tmp1, tmp2, tmp3<BR> tmp1 = convert(FirstWord)<BR> tmp2 = convert(Secondword)<BR> tmp3 = hex(tmp1 * tmp2)<BR> hash = tmp3<BR><BR>End Function <BR>--------------------------<BR><BR>Scott S

4. Pedantic Bill Guest