On Aug 25, 9:14 am, Steven D'Aprano <st...@remove-this-
cybersource.com.au> wrote:
> On Mon, 24 Aug 2009 18:01:38 -0700, Mensanator wrote:
> >> If you want your data file to have values entered in hex, or oct, or
> >> even unary (1=one, 11=two, 111=three, 1111=four...) you can.
>
> > Unary? I think you'll find that Standard Positional Number Systems are
> > not defined for radix 1.
>
> Of course not. But unary isn't a positional number system. It's a tally
> system, like my example above shows. Roman numerals are another tally
> system. Like Roman numerals, the disadvantages of unary are that you
> can't represent negative numbers, zero, or fractions, and anything but
> addition and subtraction is difficult. But if you want to use it, perhaps
> out of a sense of sadism towards your users, it's easy:
>
> def int2unary(n):
>     return '1'*n
>
> def unary2int(s):
>     n = 0
>     for c in s:
>         if c == '1': n+=1
>         else: raise ValueError('invalid unary string')
>     return n

But without insignificant leading 0's, I fail to see the relevance
of unary to this discussion. And what would you call a tally system
of radix 2? Certainly not binary.

>
> --
> Steven

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to