World: r3wp
[!REBOL3]
older newer | first last |
Pekr 21-Apr-2010 [2239] | just not probably stcp - evokes "secure" .... that would rise too much of expectations ... whereas we have no SSL in R3 :-( |
Graham 21-Apr-2010 [2240x3] | But I think it should be easy enough |
I thought you might say that ... | |
but encryption occurs at a higher level than tcp | |
Pekr 21-Apr-2010 [2243] | I know guys will not like it, but now I have "safe" way to OR/AND binaries the way I want :-) ... just not sure the way I find out the integer size is a good method ... pad-bin: funct [bin [binary!]][ bit-base: 8 * length? to-binary -1 switch bit-base [ 64 [return join #{000000000000} bin] ] ] >> (to-binary 1022) or pad-bin #{8000} == #{00000000000083FE} |
Ladislav 21-Apr-2010 [2244] | It *may be* what you want, but... What is the #{8000} binary? If it is a 16-bit signed integer, then it should be interpreted as -32768, not as 32768. |
Pekr 21-Apr-2010 [2245] | Ladislav - it came from Python's 0x8000 ... which is, if I understand guys correctly, not binary, but some kind of "binary literal integer" way of representation, which we don't have in REBOL. But, I know, that what Python mens, is 32678 ... and so that it fits my case :-) |
Ladislav 21-Apr-2010 [2246] | I think, that they confused you. It is not related to the Rebol binary datatype in any sense, it is just an alternative (hexadecimal) representation of integer. It is equivalent to date values in Rebol, where we can use alternative representations of values, e.g. 01-01-2010 , or 1/1/2010, or 1/Jan/2010. |
Pekr 21-Apr-2010 [2247x4] | Yes, I know. And I tried to help myself with binary. Suggestion to use integers, and shifting, might be accurate, but I am not here to crash my brain with operations I can't easily understand. So I try to find a convenient way. And what is convenient for me? To look into sources and to see, what is happening: >> a: to-binary 1022 == #{00000000000003FE} >> b: pad-bin #{8000} == #{0000000000008000} >> a or b == #{00000000000083FE} ... you see? I could imediatelly check, that OR was correct. And if I would be mistaken, or needed to perform shift, I can even use bitmap form, to see, what is happening: >> 2#{0000001111111110} == #{03FE} So - no, I will not use integers. And I don't have to, if my model fits what I am doing right now ... I still think that it can't fail me, and all those "you can't know what #{8000} means" are just theory for me right now :-) |
... and then - instead of Python equivalent code with 3 lines of shifting, I can just perform: append result to-char my-binary/7 append result to-char my-binary/8 ... or so I think ... | |
... the REBOL way, not just translated Python code ... | |
Is there any resolution to this topic? (Console) ... when playing with R3, I can't stand that ugly Windows "console" more and more :-) We can't even have multiline cut & paste :-( http://www.rebol.net/r3blogs/0282.html I don't remember the outcome - will we put R2 console back to Windows distro? Or wait for our own GUI based one? | |
Ladislav 21-Apr-2010 [2251] | >> ; R2 code converting integer -1 to 32-bit binary >> debase/base to-hex -1 16 == #{FFFFFFFF} ; R3 code converting the said binary to integer >> to integer! #{FFFFFFFF} == 4294967295 As far as I am concerned, it looks incompatible to me, and I would prefer -1 to be the result of the conversion in R3 |
Pekr 21-Apr-2010 [2252] | R3: >> to-hex -1 == #FFFFFFFFFFFFFFFF >> to-integer #{FFFFFFFFFFFFFFFF} == -1 |
Ladislav 21-Apr-2010 [2253] | how is that related? |
Pekr 21-Apr-2010 [2254x3] | btw - issue! is no more convertible to binary in R3. Is it because issue! is a string type, whereas binary! kind of divorces with string type? :-) |
How is that related? I don't know. Most probably I don't understand the problem you are trying to describe. Why should to-integer! #{FFFFFFFF} of said value be wrong? | |
you would expect it to be -1 probably, right? | |
Ladislav 21-Apr-2010 [2257] | I suppose, that I already wrote it abov e |
Pekr 21-Apr-2010 [2258] | hmm, but it is 4 byte value in 8 byte (64bit) environment, no? Why should it roll to -1? Well, I think it will be better for me to let the topic to those who understand it, and watch the outcome :-) |
Ladislav 21-Apr-2010 [2259] | Right, it is a 32-bit binary value being converted to a signed integer. |
Cyphre 21-Apr-2010 [2260] | Ladislav, so you think it should work this way in R3? >> to-integer #{00000000FFFFFFFF} == 4294967295 >> to-integer #{FFFFFFFF} == -1 |
Ladislav 21-Apr-2010 [2261x4] | yes |
(at least to me it makes sense) | |
But, surely, it would mean, that e.g. to-integer #{FF} should yield -1 too | |
As well as to-integer #{FFFF}, etc. | |
Pekr 21-Apr-2010 [2265] | And I am standing on the other side of the barricade ... preferring to regard this thing being always right padded, in regards to full 64bit slot :-) |
Cyphre 21-Apr-2010 [2266] | ok, but then we would need a way you convert -1 to 8/16/32/64 binary too right? |
Pekr 21-Apr-2010 [2267] | I mean - left padded ... |
Ladislav 21-Apr-2010 [2268x2] | Cyphre: Not necessarily. |
(the 64-bit result is OK) | |
Pekr 21-Apr-2010 [2270] | This is why I originally objected, and started all this discussion ... conversion is left padded (your binary value to the right), whereas OR/AND are right padded (value applied from the left) |
Ladislav 21-Apr-2010 [2271] | but, if the TO-INTEGER function obtains a 32-bit binary, it is not reasonable to expect it is not 32-bit |
Pekr 21-Apr-2010 [2272] | This is what guys tried to tell me - it is not probably being a 32 bit binary ... it is just 32 bits, placed somewhere along the way in 64 bit slot, or in the binary stream :-) |
Cyphre 21-Apr-2010 [2273] | Ladislav, ah, yes, you are right..then I think that your propsal is reasonable. |
Pekr 21-Apr-2010 [2274x3] | with such explanation, your 32 bit binary is just first 32 bits of 64 binary, and then the result might be regarded being OK,no? :-) |
but - the way Cyphre wrote his example above, it might be understandable ... simply put, if you want full slot, you have to padd it from the left ... or it is just 32 bit value, and hence should yield -1 | |
I think now I finally understand, what you mean :-) | |
Ladislav 21-Apr-2010 [2277] | first 32 bits of 64-bit binary is nonsense (you cannot convert "first 32 bits of 64-bit binary" to integer in any reasonable way) |
Pekr 21-Apr-2010 [2278] | you can - you just take first 32 bits, regard it being a 32bit binary, but you still pretend it comes from 64 bit slot ... and convert it :-) (just a joke :-) |
Ladislav 21-Apr-2010 [2279x2] | the only thing you can do is to convert "last 32 bits of 64-bit binary" |
(that is actually the description of what is going on currently in the TO-INTEGER function) | |
Pekr 21-Apr-2010 [2281] | ... and according to that description, current result is OK ... no? |
Ladislav 21-Apr-2010 [2282] | Yes, the current result is OK, if you pretend, that you did not obtain a 32-bit binary. But, I am not schizophrenic enough to be able to pretend I did not obtain 32-bit binary, when I did. |
Pekr 21-Apr-2010 [2283x3] | I think I will be OK with either solution .... (as I can fully see the consequences), I just need it being documented on some examples ..... |
I can = I can't | |
if OR and AND work "from left" ... then your proposal of #{FFFFFFFF} being -1 is logical too .... but guys might not like it, because in such a case, you can't easily convert to integer, unless you pad ... and we have no fast way to pad binaries currently ... | |
Steeve 21-Apr-2010 [2286] | what do you mean by no fast way to pad binaries ? |
Pekr 21-Apr-2010 [2287] | I mean - #{FFFFFFFF} being treated as #{00000000FFFFFFFF} for OR and AND operations .... |
Steeve 21-Apr-2010 [2288] | i don't understand why you don't chose the opposite way (dealing with integers) it's simpler and faster |
older newer | first last |