Python Forum
is there any tool to convert negative base to int?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is there any tool to convert negative base to int?
#1
is there any tool to convert negative base to int?
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
(May-21-2022, 10:48 PM)Skaperen Wrote: is there any tool to convert negative base to int?

I'm not sure what you're asking. Negative base of an exponential number? Can you give an example?
Reply
#3
just int, not exponential. also, i want to convert balanced trinary. there was, once, a Soviet computer based on balanced trinary.
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
I have no idea what you're asking. Can you give an example? What is a negative base of an int?
Reply
#5
In this Wikipedia page there is a Java function to convert a number to negative base. It should be straightforward to translate the function to Python.
Reply
#6
You can install and use 'numsys'. For negative radix numbers, you may need to feed it in as a string rather than an int.

>>> n = 12243
>>> int(numsys.rebase(str(n), '-10', 10))
8163
Reply
#7
(May-22-2022, 06:04 AM)Gribouillis Wrote: In this Wikipedia page there is a Java function to convert a number to negative base. It should be straightforward to translate the function to Python.
or ... use the Python code on that page. since i already understood negative base, i didn't think to check Wikipedia. i am glad you did and found it had code. thanks!
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
(May-26-2022, 11:20 PM)Skaperen Wrote: i didn't think to check Wikipedia
Another site to check for generic small tasks like this one is rosettacode.org. They just happen to have a python code for this problem, although their code seems to apply only to small values of the base, and it is mistakenly commented «convert from decimal» while it is actualy «convert from Python integer». The conversion between Python integers and decimals is done by the print() function and the Python parser.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cmath.rect accepts a negative modulus JMB 2 304 Jan-17-2024, 08:00 PM
Last Post: JMB
Thumbs Up Convert an Interger into any base !? [Solved] SpongeB0B 8 1,359 Jan-16-2023, 10:24 AM
Last Post: SpongeB0B
  How to do bar graph with positive and negative values different colors? Mark17 1 5,005 Jun-10-2022, 07:38 PM
Last Post: Mark17
  how to create a tool with tkinter to convert img to text rachidel07 3 2,500 Feb-05-2021, 12:21 PM
Last Post: deanhystad
  Def code does not work for negative integers. doug2019 1 1,874 Oct-31-2019, 11:00 PM
Last Post: ichabod801
  offset can not be negative in File.seek()? jollydragon 6 6,872 Sep-28-2019, 03:08 AM
Last Post: jollydragon
  Positive to negative bernardoB 6 4,280 Mar-13-2019, 07:39 PM
Last Post: bernardoB
  convert non-string with explicit base jacklee26 5 16,066 Nov-06-2018, 06:50 AM
Last Post: jacklee26
  Python regex with negative set of characters multiline sonicblind 2 3,357 Jul-30-2018, 08:43 PM
Last Post: sonicblind
  negative to positive slices Skaperen 3 3,595 Jan-29-2018, 05:47 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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