Questions tagged [base-conversion]
40 questions
6
votes
1 answer
Base conversion puzzle
Here's an old puzzle: Let $s$ be a string of decimal digits ($s[i] \in \{0,\dotsc, 9\}$). Define a function $f(s)$ as follows:
Interpret $s$ as a decimal number, $n_{10}$, and convert $n$ to its octal equivalent, $m_8$.
Now treat $m$ as a decimal…
Rick Decker
- 15,016
- 5
- 43
- 54
5
votes
1 answer
How to find a basis which is guaranteed to need 9 or less characters to represent a 12 digits number?
I'm trying to map a 12 digit number into a fixed width file. For a number of reasons, it must be compressed in such a way that it is guaranteed to be less than or equal to 9 characters (alpha numeric is fine). My first thought was a change of…
user34961
- 59
- 1
5
votes
1 answer
Base transcoding with minimum storage and complexity
I want to reversibly transcode arbitrary information (a digital signature), initially $n$ bits, into symbols in an alphabet with $s$ symbols, with little space loss. In my application‡ $s=45$. Thus I can e.g. transcode $n=192$ bits into $m=\lceil…
fgrieu
- 519
- 3
- 14
4
votes
3 answers
Algorithm to convert decimal number to binary
I am reading this material to understand the basics of number system.
I am stuck at a point in that material where it writes the algorithm to convert a decimal number to binary number.
The heading of that part where I am stuck is Decimal to Base
The…
Ravi
- 151
- 1
- 1
- 6
3
votes
0 answers
How does the Bitcoin Algorithm for Converting to Base 58 Work?
I've been trying to create a function in TypeScript for converting to and from base58. I'm pretty familiar with base conversion generally: divide a number by a target base, and take each remainder as a digit of the conversion from right to left,…
devbanana
- 131
- 2
3
votes
3 answers
Algorithm to convert a fixed-length string to the smallest possible collision-free representation?
I have a US-based telephone number (in the format 000-000-0000) and need to convert it to a "shorter" representation. Using base32/64 produces too long of a string. I've discovered CRC-16, which produces a string of length 4, however, I'm not sure…
anemaria20
- 131
- 1
- 2
2
votes
2 answers
Time complexity of expanding decimal to new base
There is already a post on this topic on stackoverflow.
Nevertheless, I am asking the question here again, primarily because I do not understand the answer given there, and also because I have some takes on the problem I would like to supplement…
sss
- 83
- 10
2
votes
2 answers
4-digit 5's complement of a negative number
Let $n = -13, \ k = -24$
How do I find the 4-digit 5's complement of each number? What would be the result of $n + k$ in complement representation?
I understand how to calculate $n$-digit, 2's complement. I convert it to base 2, invert and add…
yarafoudah
- 147
- 4
2
votes
2 answers
Finding the values of x and y using base 8
In finding the values of x and y, if (x567) + (2yx5) = (71yx) ( all in base 8) I proceeded as under.
I assumed x=abc and y=def and followed.
(abc+010 def+101 110+abc 111+101)=(111 001 def abc) //adding ()+()=() and equating LHS=RHS.
…
tonny
- 59
- 1
- 4
- 9
2
votes
1 answer
Are leading zeros necessary when referring to other bases in certain contexts?
I recently took a computer science test where one question was as follows:
Each RGB color value can range from _____ to _____ in decimal, _____ to _____ in binary and _____ to _____ in hexadecimal.
I answered,
Each RGB color value can range from…
Paradox
- 23
- 4
2
votes
0 answers
Converting from m base to n base without arithmetic operations (Where m
I have been working the last 8 years in try to convert from base n to base m without artihmetical operations.
My hypothesis is that by the same way that is possible convert bases without division (see the tables bellow.) based in a literal…
Fabio Andrés
- 121
- 4
2
votes
1 answer
Conversion from octal numerical system to binary numerical system
I know that in order to convert a numeral in base-8 to a numeral in base-2 I can write each octal digit as a binary word of 3 bits.
I know that 2^3 = 8 that is exactly the dimension of the base of the octal system.
I just cannot understand the…
zar
- 23
- 2
1
vote
1 answer
How to convert between bases partially?
I have some large number $n$ in base $b_1$ and I want to convert it to base $b_2$. $n$ is about a million decimal digits long, therefore it's impractical to convert it as a whole. However I don't need the entire $n$, just some arbitrary slice of it…
jan
- 279
- 2
- 6
1
vote
1 answer
Is there an online algorithm for radix conversion?
Suppose I have $P$, which is the base-$p$ representation of an integer $n$ and I want to calculate it base-$q$ representation $Q$. The obvious algorithm is: interpret $P$ to obtain $n$, then calculate $Q$ from $n$. This is easy.
But if $n$ is very…
Mark Dominus
- 1,567
- 14
- 22
1
vote
1 answer
Shortest decimal expansion within binary interval
Consider an interval $[x-2^n,x+2^n]$ defined by a binary float $x$ and a power of two $2^n$ typically much smaller than $x$. I would like to know whether an efficient algorithm exists to determine the shortest decimal expansion within the interval.…
equaeghe
- 200
- 1
- 8