jNizM wrote:or you let the dll's calc this for you
yes, yes I could have a system DLL do the conversion. But as I said, I am doing this for fun. Using a DLL would be a little like strapping a camera to your butler and tossing him out of a plane, then watching the video. Not as much fun.
just me wrote:As a start, the parse-loop will only work properly for strings containing only characters which are represented by exactly one byte.
Yes, using only 8 bits limits usable characters to the first 255 in the ascii/unicode table, but that covers most English characters.
just me wrote:The expression is performing a & (bitwise and) operation upon two bytes. One of the bytes is retrieved by the parse-loop and contains various values, the other byte is always 1. The & operation compares the two bytes and sets all bits in the result which are set in both bytes. The result of Asc("A") & 1) would be:
Code: [Select all] [Download] GeSHi © Codebox Plus
01000001 ; Asc("A") = 65 = 0x41
00000001 ; 1 = 0x01
--------
00000001
As you can see, the value 1 will always check only the least-significant / rightmost bit. To check the other bits this way they have to be shifted / moved right to position 0, and that's exactly what >> (8 - a_index) does, shifting 7 positions to the right in the first iteration, 6 in the second, and 0 in the last. So the bits are compared in the order 7 to 0. The result of the & operation is either 1 (if the rightmost bit is set) or 0 (if not) and appended to bin.
Yes, I think I start to get it. That bit of code is taking the decimal number for a character, and using >> and & to generate that number's binary code by appending 1s and 0s one at a time to the bin var. The math still confuses me but at least there is hope.
just me wrote:A bit clearer now?
Yes, and nice pun.
just me wrote:Edit: As a hint for bin2txt(): x += x =x * 2 = x << 1 (shifting one position to the left eqals multiplying by 2 eqals adding a value to itself).
Yeah, I can see the
x += x but it is the
(a_loopfield = "1")part that I don't understand. noname says it is converting the literal 1 and 0 characters in the input string back into integers, but how is it doing that? I have often appended an empty string to force treating numbers as strings, but I have no idea why this syntax would do the opposite.
noname wrote:The (A_LoopField="1") seems to convert the "string" 1 or 0 to "number" 1 or 0 so it can be used to count up.
OK, but how is it doing that? I know appending non integers or an empty string to an integer forces a script to treat the integer as a string, but I don't see anything in the docs about doing the opposite. I just have no reference point for the syntax of that bit of code.
noname wrote:The position of the 1 in the binary will determine how many times it will loop.In pos second from the left it will loop 7 times and gives 128 so all positions with 1 will add up to give the total.
... I don't understand that at all.
noname wrote:Ithink the function should be corrected like this by initialising x:=0
Thank you! I have made the change to my code. I am looking at this and I can't see what difference that makes to how this works. Somehow having x start as 0 instead of blank changes the math, but I can't see how just from looking at it. Again, math is not a skill I have.
Thank you all for responding. I will keep looking at what you posted and trying to figure it out. if anyone wants to add to this or clarify some points please bring it on!