Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
integer bases
#1
when a sequence of digits is prefixed with "0x" in many contexts, one of them being the int() function in python with "0" as argument 2, it means the digits that follow are base 16 (hexadecimal).  likewise, a prefix of "0o" can mean octal, in many contexts, though not as many.  and the prefix of just "0" will also mean octal, but only in python2 when using a base of 0 in int().  and then there is "0b" for binary.

what i am wondering is, if any of you have seen other prefixes like this for other bases such as duotridecimal (32).  i'm not limiting this to just python that you have seen it in, though it is for a python project.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Smalltalk:  BASErNumber   (with BASE <=36)
(https://en.wikipedia.org/wiki/Smalltalk#Literals)

Samples:
2r10
8r12345670
10r1234567890
16r1234567890abcdef 
36r1234567890abcdef...xyz
Reply
#3
so, a number in decimal, followed by 'r' makes the number be interpreted in that base.  but 'r' is used in bases 28 and up.  you can see it with int('r',36) (27).  while using it as a prefix can keep it apart from the actual number, it can get confusing, particularly if fixed base conversion also needs to support detecting and skipping a prefix.  int('36r',36) (4131) shows the trouble.  but this might be an interesting idea with a special character like '#'.

int('36r1234567890abcdefghijklmnopqrstuvwxyz',36) = 439489306199522966786723633568956982924420943317067045010171
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Ada takes char "#"
https://www.adacore.com/gems/ada-gem-7

Mathematica:
b^^nnnn is a valid number in base b (with b ranging from 2 to 36)
Reply
#5
somewhere, though i cannot find it so i may have deleted it ... i wrote a base conversion program that went beyond base 36 by having "digits" be ints in a list.  i may have to redo that.

but for now a string conversion is all i am doing, and up to base 36 is just fine, or maybe up to base 64 with case handling and 2 extra digits.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
That is fine upto 64.
Reply
#7
but who really needs numerical bases that high.  i'm pushing it with my code, which supports bases 32 and 36.  we do already have base64 and even base85 for binary data as byte sequences.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
Thanks for the code.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  About integer objects vs integer values Nwb 18 4,099 Apr-29-2019, 07:41 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020