Script For randomly Generating Chinese names

Source: Internet
Author: User
Tags binary to decimal decimal to binary
<%
Dim I
Dim J
Dim HS
Dim he
Dim ls
Dim le
Dim result
Result = ""
HS = 177.
He = 247
Ls = 1, 161
Le = 254
Dim max_num
Max_num= 65536
Randomize
For I = 1 to 4
Temp1 = dec2bin (INT (HE-HS) * RND () + HS)
Temp2 = dec2bin (INT (le-ls) * RND () + ls)
Result = Result & CHR (binarytodecimal (temp1 & temp2)-max_num)
Next
Response. Write result &""
%>
<%
'Below is the function
Public Function dec2bin (mynum) 'decimal to binary
Dim loopcounter
If mynum> = 2 ^ 31 then
Dec2bin = "too big"
Exit Function
End if
Do
If (mynum and 2 ^ loopcounter) = 2 ^ loopcounter then
Dec2bin = "1" & dec2bin
Else
Dec2bin = "0" & dec2bin
End if
Loopcounter = loopcounter + 1
Loop until 2 ^ loopcounter> mynum
End Function

Public Function binarytodecimal (binaryvalue) 'binary to decimal conversion
'Returns the decimal equivalent of a binary number
Dim idx
Dim TMP
Dim result
Dim digits
Digits = Len (binaryvalue)
For idx = digits to 1 step-1
TMP = mid (binaryvalue, idx, 1)
If TMP = "1" then result = Result + 2 ^ (digits-idx)
Next
Binarytodecimal = Result
End Function
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.