Re: Draft of Binary module

On 13/03/2013 17:20, Adam Retter wrote:
> A second stream of consciousness:
>
> I feel very uneasy about representing octets using integers. So I ask
> myself why? Is it history - i.e. eXist and Zorba (maybe others)
> represent octets as octal strings and allow for the conversion of
> octal to/from decimal with functions.
Odd, I haven't seen octal used in anger for about 25 years, I thought it 
was completely obsolete. But then I guess I've managed to avoid writing 
in C. Every since the industry standardized on an 8-bit byte, 
hexadecimal has seemed much more natural.
>
> An octet is implicitly in Base 8
Eh? if it's anything, surely it's implicitly in base 2?
> , so why would I then want to
> manipulate it as thought it were Base 10 (but without converting it to
> Base 10). This just doesnt make sense to me -
>
> If I understand correctly -
>
> bin:binary-to-octets(xs:hexBinary("FFFF"))  would give me (255, 255)
Seems natural to me.
>
> Rather if you want to go to base10 then
> bin:binary-to-radix(xs:hexBinary("FFFF"), 10) could give me 65535.
But there's nothing intrinsically decimal about the value 65535, other 
than the way it's being printed on the page.

bin:binary-to-radix(xs:hexBinary("FFFF"), 17) would give you exactly the 
same integer - it only becomes base 17 when you convert the integer to a 
string to display it.
>
>
> All of the bitwise operators seem to operate on xs:hexBinary
Yes, I think it's a separate discussion whether bitwise operators on 
integers would be more useful. I think the main problem is that we don't 
have hex literals, so we can't say $x & xFF00, instead we have to say either

(1) if we use hexBinary: bin:and($x, xs:hexBinary("FF00"))
(2) if we use base64Binary: bin:and ($x, xs:base64Binary("/wA="))
(3) if we use integer: bin:and($x, 65280)

None of these is nice, but the first seems to me the most readable. If 
we go with (and/or/not) working on integers, then perhaps we should also 
have functions

bin:hex("FF00") => 65280

bin:octal("177400") => 65280 (since you're telling me that there are 
indeed people who still use octal...)

Michael Kay
Saxonica

Received on Thursday, 14 March 2013 08:59:55 UTC