Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [base-conversion]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
26 views

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. ...
Paradox's user avatar
  • 23
0 votes
0 answers
30 views

General Base Converting Algorithm

I am looking to implement a general base conversion algorithm. I was wondering if there already exists such a thing, since I couldn't find one. Currently, I am able to go from int to int, but I also ...
Tim's user avatar
  • 1
1 vote
2 answers
167 views

Fast string-to-integer algorithm

I work with big integers that I need to convert to and from strings, and to and from different bases. In JavaScript, BigInt allows to convert an integer to a string in a chosen base by doing: ...
Zwyx's user avatar
  • 123
1 vote
2 answers
179 views

How does Decimal to Binary conversion algorithm work?

I'm reading a book which says that to transform a number from decimal representation to binary representation you have to follow these steps: Take the integer part (the one before the point) of the ...
ela's user avatar
  • 315
5 votes
1 answer
75 views

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 ...
fgrieu's user avatar
  • 519
1 vote
2 answers
317 views

Why does the hash function in Rabin—Karp produce unique hashes?

The Rabin–Karp algorithm uses a rolling hash function to find a substring matching a pattern: $$ H = c_1a^{k-1} + c_2 a^{k-2} + c_3 a^{k-3} + \cdots + c_k a^0, $$ where $a$ is a constant, $c_1\ldots ...
user1968919's user avatar
3 votes
0 answers
143 views

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 ...
devbanana's user avatar
  • 131
1 vote
1 answer
38 views

algorithm to check the existence of $b-1$ in $(n)_b$?

Given an integer number $n$ (in base 10) and a base $b$, determine whether the representation of $n$ in base $b$, $(n)_b$ has a coefficient with value of $b-1$. ...
Math-fort's user avatar
  • 173
1 vote
0 answers
66 views

Computability of base-conversion for streams

With regular numbers it is always possible to convert them from one (integer) base to another. But what happens if we consider numbers for which their magnitude is not known in advance, or in other ...
prog's user avatar
  • 105
0 votes
1 answer
777 views

What does it mean when asking to Convert 16-bit binary numbers to two 8-bit signed integers (two’s complement) in decimal

The question is Convert the following 16-bit binary numbers to two 8-bit signed integers (two’s complement) in decimal. i. 0b 0011 0110 1101 0100 I first flipped it and added 1 to it which equaled ...
Tenkin's user avatar
  • 3
0 votes
0 answers
121 views

How to convert a string (number representation) to an arbitrary base using custom alphabet?

I'm trying to figure out an efficient way (without recursion) to convert a string (number representation) from one arbitrary base to another using custom alphabet. But I cannot think of a very fast ...
AlekseyHoffman's user avatar
1 vote
1 answer
3k views

Arithmetic on signed 12-bit octal number stored in sign magnitude form

What is 4365 − 3412 when these values represent signed 12-bit octal numbers stored in sign-magnitude format? The result should be written in octal. Show your work. Octal to binary: 4365: 100 011 110 ...
Haslo Vardos's user avatar
0 votes
1 answer
41 views

Why is the carry of any n base system equal to the radix in arithmetic?

In binary the carry/borrow is 2, in hex the carry is 16. What's the reason for this?
Zee's user avatar
  • 1
1 vote
1 answer
2k views

Conversion of fractional part of a hexadecimal number to binary

The Number is given as : (C012.25)Hexadecimal I have to convert it into octal . So I converted it into Binary First and got the result as : 1100000000010010.01000000 (Since each bit in hexadecimal ...
Dan's user avatar
  • 15
1 vote
2 answers
241 views

Streaming digit-to-digit conversion from decimal to hexadecimal

I am looking for a streaming algorithm for converting a decimal number to a hexadecimal number. I am assuming the input is a string represention of a decimal number (i.e., each character is a decimal ...
ljleb's user avatar
  • 138
2 votes
0 answers
111 views

Converting from m base to n base without arithmetic operations (Where m<n )

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 ...
Fabio Andrés's user avatar
2 votes
1 answer
68 views

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 ...
zar's user avatar
  • 23
0 votes
0 answers
99 views

An interesting compression algorithm idea

I stumbled on this paper about compressing images using a kind of odd, but interesting idea. It seems pretty easy to implement and I was wondering if there is something wrong with it that I haven't ...
dearn44's user avatar
  • 125
3 votes
3 answers
2k views

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 ...
anemaria20's user avatar
0 votes
1 answer
1k views

Find n-th number in a number system with only 3 and 4

Given a number system with only 3 and 4. Find the nth number in the number system. There is a solution given here but its very vague without explaining the mathematics/ concept behind it. Can someone ...
user248884's user avatar
2 votes
2 answers
581 views

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 ...
sss's user avatar
  • 83
2 votes
2 answers
1k views

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 ...
yarafoudah's user avatar
1 vote
1 answer
97 views

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 ...
jan's user avatar
  • 279
1 vote
1 answer
342 views

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 ...
Mark Dominus's user avatar
  • 1,537
1 vote
1 answer
71 views

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 ...
equaeghe's user avatar
  • 190
0 votes
2 answers
879 views

Convert a decimal floating-point number into a binary floating-point number

Let's say I have a decimal floating-point number, i.e. a mantissa and precision (negative exponent), both represented as integers. How do I convert this into a binary floating point number (of the ...
Noldorin's user avatar
  • 111
0 votes
0 answers
123 views

As a number (base 10) approaches infinity, what would be longer? Represented in BCD or Base-2?

My professor asked this question in his lecture class and I can't figure out the answer. My guess is BCD because you can't use up all the numbers (10 to 15), so you eat up space?
zuzu's user avatar
  • 101
0 votes
0 answers
481 views

How can I convert a binary number to a base-4 number with a Turing Machine?

I'm looking for some guidance to get me going. I assume (and please correct me if I'm wrong) that it'll need 2 tapes and by reading various resources, I found that it might be easier with the binary ...
Void's user avatar
  • 99
-1 votes
1 answer
4k views

Writing a Turing Machine that convers a number from binary to decimal

I'm trying to write a Turing machine that can convert a number in binary representation to a number in decimal representation. For example if the input on the tape is 1101 the output should be be 13. ...
greps's user avatar
  • 101
0 votes
1 answer
64 views

Optimal way for the remainder [closed]

I want to know if for any base the most significant digit is 1 or not. Here is the code: ...
rresol's user avatar
  • 111
-1 votes
1 answer
453 views

Newbie: hexadecimal editors to make sense of binary files [closed]

As a disclaimer, I am a geophysicist, not a computer scientist. I have a binary file with a whole bunch of data in it (it is a large file; 221 MB). I am trying to convert this to something usable but ...
Darcy's user avatar
  • 111
1 vote
1 answer
311 views

Convert non-integer decimal to octal

I follow a course in Computer Architecture and I'm making exercises on number conversions. Now one of the questions asks me to convert 251.5625 to octal and hexdecimal base. No further info is given. ...
Pieter Verschaffelt's user avatar
4 votes
2 answers
19k views

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 ...
Ravi's user avatar
  • 151
-2 votes
1 answer
106 views

Hex to decimal conversion [closed]

I'm converting hex ( in positional fractions) to decimal question : 0x3c.e8 my attempt: $3*16^1 + 12*16^0$ yields $60$ $ 3c$ = $ 60 $ in decimal so i know its 60. then $.e8 *10 $ (since I want ...
learnmore's user avatar
1 vote
1 answer
1k views

Efficient algorithm for conversion of hexadecimal fraction to decimal fraction

Let's say I have some very long hex fraction like this: 0.3F30A21306AEFCBADE3230A593EFAEB395A39E What are some algorithms with an acceptable complexity to ...
Joseph Nields's user avatar
5 votes
1 answer
298 views

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 ...
user34961's user avatar
0 votes
1 answer
180 views

$25_r = 23_{10}$ solve for the base r

first of all this is a homework question and I don't want the solution. I just want a reference to how to solve similar questions like this. I believe it's explained my course textbook, "Computer ...
167165's user avatar
  • 3
0 votes
1 answer
416 views

conversion to base-R numbers

I am reading Algorithms 4th edition by Robert Sedgewick and am stumped at a particular problem. On page 460 of the book the author is describing a technique to hash strings and use prime numbers for ...
Deepak's user avatar
  • 101
2 votes
2 answers
1k views

Finding the values of x and y using base 8 [closed]

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 ...
tonny's user avatar
  • 59
6 votes
1 answer
163 views

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 ...
Rick Decker's user avatar
  • 14.8k