ASP experience (binary turn 10 credits) [first]

xiaoxiao2021-03-06  46

<% a = 01101110 'eight bits 2 into the number, casually change B = len (a) m = 0 for i = -b TO-1 D = MID (A, I B 1, 1) c = (D * 2) ^ (ABS (I) -1) IF (ABS (i) = 1) AND (D = 0) Then 'because 0 ^ 0 is 1, but actually we need 0 Response.write C-1 & "=" Elseif ABS (I) = 1 Then Response.write C & "=" Else Response.write C & "END IF IF (ABS (i) = 1) AND (D = 0) Then 'This is used by the operation result, is The same, we need 0, more than one 1, button to go to it M = M C-1 Else M = M c end if next response.write (m)%> This is a 2-way turn of ten-based code Started an old error, found that the MID () and Len () functions only started to count the first one, and push Left () and Right () should also be corrected, first The MID (A, 1, 1) is not the eighth, but it is impact that he summarizes the size of a number of digits should be reduced by the number of bits of the import value, such as 10 yuan. The import value is 10 so decimal turn is 1 * (10 ^ (2-1)) Other digits, such as 111 is 1 * 100 1 * 10 1 * 1 100 is (10 ^ (3- 1))) Waiting binary 001 is 0 * 4 0 * 0 1 * 1 According to this above algorithm but encountered a problem, our loop is from high to low, but the MID () is from left. It is not possible to find a half-day discovery that the loop cannot be mentioned at the same time, such as for i = -6 to -1: m = 1 to 6, no results, according to a simple addition i b 1 i is always small, then the whole The result has been increasing, and the problem of the bit value is opposite to the number of digits (because the number of left bisses is larger, but the MID () is from the left I can only meet the number of digits. Continuously complicate, but also to meet the MID () continuously to achieve the right stretch), 0 ^ 0 is 1, which is 1, the first one is 0 (0 * 2) (1-1) 1, but actually zero the IF condition to achieve special circumstances, special treatment, the final is the income problem I have always thought about how to achieve the accumulation of the cycle speech If M = C C is so terrible and cannot be connected , C will be re-assigned each time but I think that M can achieve the value of each M is assigned, he does not belong to a loop variable. M = 0 First cycle m = mc = 0 64 second cycle, M = 64 M = M C = 64 32, this is the same as if I assign M value to M, outside the loop statement In this way, at the end of the cycle, you can output the maximum value outside the process. You do not believe that you can put it in the loop to see if he became a local variable rather than a global variable.

转载请注明原文地址:https://www.9cbs.com/read-110168.html

New Post(0)