r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3]

Maxim
19-Apr-2010
[2067x3]
binary is a string of  bytes, so that it returns 8 bit integers to 
me is VERY usefull.
what you say is equal to:

a: [1 2 3 4 5 6]
a/3
== [3]
binary is a series, and indexes return, like all other series, the 
element which constitutes it at the index you give it.
Pekr
19-Apr-2010
[2070]
OK, I can accept that ... but is R3 OR operation, performing OR on 
the higher bytes correct?
BrianH
19-Apr-2010
[2071]
If you are concerned about alignment, manage it yourself. The behavior 
is extremely consistent, so that such management is easy.
Pekr
19-Apr-2010
[2072x2]
Brian:  how is that supposed to be easy? The way it is, I have to 
count on the internal representation binary size - here 64 bits ...
I am asking binary 1024 to be ORred with binary #{8000}, the result 
is imo crap :-)
BrianH
19-Apr-2010
[2074]
Yes, but that 64 bits is a known, consistent quantity. Very predicatble.
Pekr
19-Apr-2010
[2075x2]
but the result is imo wrong anyway, no?
This is correct:

>> (to-binary 1022) or (to-binary 32768)
== #{00000000000083FE}
BrianH
19-Apr-2010
[2077x2]
No, binaries are right-padded. You should have been ORing with a 
binary of the proper sixe. R3 was nice enough to add the 0s that 
you didn't provide. It's just your assmption that was off :(
sixe -> size
Pekr
19-Apr-2010
[2079x5]
no, it is not ...
>> to-integer #{8000}
== 32768
What assumption are you talking about? If you were right, then above 
binary should be paddedd too ...
I was orring original converted 1022 with 32768 and got a crap ...
If I should care about internal representation of binary, then it 
is not usable datatype for me. How are my operations supposed to 
be fast?
BrianH
19-Apr-2010
[2084]
TO-INTEGER and TO-BINARY integer left-pad. OR and AND don't pad at 
all (in theory), they just make up for your error in not providing 
the whole binary. It is like blocks and none.
Pekr
19-Apr-2010
[2085]
can't you see that? Following iperations are imo compatible, and 
should provide me with identical results ...

>> (to-binary 1022) or (to-binary 3278)
== #{0000000000000FFE}

>> (to-binary 1022) or #{8000}
== #{80000000000003FE}

>> to-integer #{8000}
== 32768
BrianH
19-Apr-2010
[2086]
You were assuming padding, when there is no way to pad those operations 
without breaking someone's assumptions. If you are doing binary conversions 
and working with binary values you are assumed to know what you're 
doing.
Pekr
19-Apr-2010
[2087x2]
simply put, in second case, 1022 is not orred with 32768
No, OR/AND should be applied from the right side, not from the left 
side ....
Maxim
19-Apr-2010
[2089]
pekr,  there are things in Computer science which just are.   Just 
like there are things in maths, which just have to be accepted. 


R3 isn't inventing much of anything here, its actually much closer 
to normal boolean algebra than R2 ever was... FINALLY.   


in binary algebra, normally, things are right padded when sizes don't 
match... that's just how the maths behind it where defined long ago.


binary manipulation is an advanced topic, and you can't assume anything.
BrianH
19-Apr-2010
[2090]
Simply put, you are assuming that TO-BINARY and TO-INTEGER are reversable 
when you don't provide the whole binary equivalent of the integer. 
There is no reason that this would be true.
Pekr
19-Apr-2010
[2091x2]
non reversable operations are evil ... can't remember the case, but 
we already had such discussion in regards to some R2 area ....
Once again - you are imo wrong. R3 should not allow to enter any 
other than full binary padded format then!
BrianH
19-Apr-2010
[2093]
There's no reason that the operation *would* be reversible. The TO-INTEGER 
was correcting for an incomplete binary in a DWIM way. If you had 
provided the whole binary it wouldn't have had to do that. And the 
TO-BINARY had a whole integer, so it didn't have to correct.
Pekr
19-Apr-2010
[2094x2]
How is that in Python, they can safely do it?

 elif l < 0x4000:
            l |= 0x8000
            self.writeStr(chr((l >> 8) & 0xFF))
            self.writeStr(chr(l & 0xFF))

The second line is - l: l or #{8000}
What if I will have 32 or 128 variant of REBOL? Will I have to adjust 
my expressions, hence change my code? There is no reason to not perform 
OR/AND on the lowest byte, not the highest byte imo ...
Maxim
19-Apr-2010
[2096]
pekr,  to-integer is a helper func.  its like form, not mold.

you shouldn't be using to-integer.. for binary arithmetic.

rebol is reversible:
>> b: to integer! a
== 32000

>> b: to binary! a
== #{0000000000007D00}

>> a: to integer! b
== 32000
Pekr
19-Apr-2010
[2097]
I mean 32bit or 128bit
BrianH
19-Apr-2010
[2098]
It is not that Python was doing it "safely", it was that Python was 
doing it differently when there is no standard for what to do here.
Pekr
19-Apr-2010
[2099]
OK, one other areas, where R3 makes things difficult ...
BrianH
19-Apr-2010
[2100x2]
Pekr, binary operations are assuming that the binary is part of a 
stream. The "lowest" byte could be megabytes away.
And I was wrong, the Python in your example was not operating on 
binaries at all, it was operating on integers that were specified 
in hex syntax, which is a completely different thing that REBOL has 
no support for at all. Not the same thing.
Pekr
19-Apr-2010
[2102]
binary streams and binary arithmetics are different issue to me ...
BrianH
19-Apr-2010
[2103]
0x8000 and #{8000} are completely different concepts.
Maxim
19-Apr-2010
[2104]
pekr... here I must say, you really do not know what you are talking 
about.


all the binary changes brought to R3 are due to user responses about 
how fucked up it really was to use binary stuff in R2.   really. 
 I had to build binary data-driven TCP servers in R2, for example, 
and I had to use so many shitty work-arounds and fix up numbers .. 
it was an ordeal.


R3 makes binaries, clean, no hassle and simple.  they are a simple 
series of bytes, nothing more.


they are manipulated from the start to the end in that order.  that's 
all there is to it.
BrianH
19-Apr-2010
[2105]
0x8000 is an integer specified in a different syntax, one which REBOL 
has no equivalent to but C does.
Maxim
19-Apr-2010
[2106]
and 0x8000 will be a different value based on what variable type 
it is assigned to.

0x8000 can be:

 #{8000}, #{00008000}, or  #{0000000000008000}

you can't tell .
Pekr
19-Apr-2010
[2107x2]
So once again - I can work with two binaries being converted at the 
SAME time:

>> (to-binary 1022) or (to-binary 3278)
== #{0000000000000FFE}

But I can't work on two binaries stored at different time:

>> l: to-binary 1022
== #{00000000000003FE}

>> l or #{8000}
== #{80000000000003FE}
Max - please stop this fanboyism. I know why R3 was brought to us, 
and I know how fucked up R2 binary was. I am glad we are converting 
to binary as one value, not as separate values, like in R2, that 
was not usefull. But my above case will make headache to many ppl, 
I can bet ...
Maxim
19-Apr-2010
[2109]
pekr... have you been reading... #{8000} is NOT A NUMBER its a SERIES 
OF BYTES.


you keep refereing to binaries as if they where numbers.  THEY ARE 
NOT
Pekr
19-Apr-2010
[2110x2]
and 0x8000 will be a different value based on what variable type 
it is assigned to.
 ... do you REALLY mean it? 0x8000 is just one value, period ...
... and you are talking about CERTAIN binary value as of stream of 
unknown position, hence not having value at all :-)
Maxim
19-Apr-2010
[2112]
to-binary 1022  creates a string  16 bytes (64 bits).
Pekr
19-Apr-2010
[2113]
no, it creates a  binary :-)
Maxim
19-Apr-2010
[2114x2]
pekr you seem to miss that a value and a litteral are two different 
things.
I meant a value stored in ram.
Pekr
19-Apr-2010
[2116]
OK, so in my above case, I am supposed to pad #{8000} to #{00008000} 
... what the hell do I do, if I am on 32 bit R3 version, not having 
64 bit integer? How do I know?