Questions tagged [base-conversion]

Conversion of numbers between positional numeral systems. Most common systems are decimal, binary, hexadecimal etc.

Filter by
Sorted by
Tagged with
4 votes
1 answer
193 views

Convert real numbers between factoradic and positive integer bases

This prompt asked you to convert back and forth to factoradic, but is very limited in scope (only decimal integers from 0 to 10!-1). Your task in this challenge is to reach just a bit further and ...
guest4308's user avatar
  • 179
7 votes
1 answer
258 views

Literate Programming in Base 26

Your task is to convert non-empty strings - between strings using the 26 letters, and programs, which are strings of bytes, where each byte has 256 possible values. You should use the same codepage ...
Command Master's user avatar
4 votes
5 answers
149 views

Base consecutive k-frequency counter [closed]

Given a base \$k\$ as well as two indices (also passed in base \$k\$, call them \$s\$ and \$e\$) return a list containing a frequency count of all base-\$k\$ digits occurring between \$s\$ and \$e\$ ...
Michael Klyachman's user avatar
11 votes
34 answers
2k views

Convert binary to unary

The title says it all; Given a number in the binary (base-2) number system, output the same number expressed in unary (base-1). You should take the binary number as a string (optionally with a ...
noodle man's user avatar
  • 5,527
19 votes
10 answers
3k views

Numbers that can be negated by reading backwards

Balanced ternary is a modified version of ternary (base 3), using the three digits 1,0 and -1...
bsoelch's user avatar
  • 5,825
15 votes
6 answers
1k views

Cube calendar numbers

Credit: Marco Verch CC BY 2.0 A two-cube calendar, as shown in the picture, uses two cubes with digits painted on the faces to display the date. For dates in the range 1-9, a leading zero is used (&...
AnttiP's user avatar
  • 7,828
11 votes
16 answers
986 views

Multibase Numbers

(Similar: Through the bases) Normally, our number system is base ten, with the digits 0123456789. However, we can increase or decrease the base count (so ...
Infigon's user avatar
  • 561
15 votes
21 answers
743 views

CGAC2022 Day 16: Playing with bits, Part 2

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. As soon as the Elves get bored with the last week's game, Bin comes up with a new game. The rules are similar, ...
Bubbler's user avatar
  • 73.8k
13 votes
25 answers
2k views

Output the length of (the length plus a message) [duplicate]

The task is simple. You're given an arbitrary string message. Return that message prefixed with a number, such that the length of that number plus the message equals the number. In other words, the ...
virchau13's user avatar
  • 499
19 votes
25 answers
2k views

Carry-less sum given a base b

Given a list of positive integers \$\mathcal I=I_1,I_2,I_3,...,I_n\$ and a base \$b>1\$ return their "carry-less sum", i.e. represent \$\mathcal I\$ in base \$b\$ and sum digit-by-digit ...
loopy walt's user avatar
20 votes
30 answers
2k views

Convert from variable-width Two's Complement to Integer

Take an input, and convert it from Two's Complement notation (binary where the first bit is negated, but the rest are taken as normal) into an integer (in a somewhat standard output form). Input can ...
Romanp's user avatar
  • 1,357
25 votes
16 answers
3k views

Convert to base i - 1

Given \$ i = \sqrt{-1} \$, a base-\$ (i - 1) \$ binary number \$ N \$ with \$ n \$ binary digits from \$ d_{0} \$ to \$ d_{n - 1} \$ satisfies the following equation. $$ N = d_{n - 1} (i - 1) ^ {n - 1}...
xiver77's user avatar
  • 2,325
12 votes
22 answers
1k views

Convert a string of ASCII characters to base-3 equivalents

Task similar to this one. Take a string of ASCII characters and convert it to base-3 equivalents separated by a space. For example: Hello, world! Should be ...
sinvec's user avatar
  • 1,885
12 votes
14 answers
1k views

Lowest integer with no common digits between given bases

Challenge Given a list of bases for positional numeral systems as input, output the lowest positive integer that when represented in those bases they have no common digits. The input list can be ...
Kjetil S's user avatar
  • 5,497
3 votes
11 answers
490 views

Concatenate characters' indexes in the alphabet in the given numeral system

Given a word, get the indexes of each letter in the alphabet. For example: uncopyrightable becomes: ...
double-beep's user avatar
17 votes
11 answers
2k views

Write a number in overflowed binary

We all know how binary conversion works: the sequence of bits $$ b_1, b_2, ..., b_{n-1}, b_n $$ encodes the number $$ b_1 \times 2^{n-1} + b_2 \times 2^{n-2} + ... + b_{n-1} \times 2^1 + b_n \times 2^...
pxeger's user avatar
  • 23.3k
13 votes
9 answers
1k views

Bijective meets mixed base

Background A bijective base \$b\$ numeration, where \$b\$ is a positive integer, is a bijective positional notation that makes use of \$b\$ symbols with associated values of \$1,2,\cdots,b\$. ...
Bubbler's user avatar
  • 73.8k
10 votes
35 answers
2k views

How long is the number in this base?

Given a positive integer \$n\$ and another positive integer \$b\$ (\$1 < b < 36\$), return the number of digits/length of \$n\$ in base \$b\$ ...
2x plus 1's user avatar
  • 133
13 votes
9 answers
836 views

Convert to a non-adjacent form

Consider a form of binary where digits can be any of \$1\$, \$0\$ and \$-1\$. We'll still call this "binary" because we convert the digits from base two. For example, $$\begin{align} [1, 0, -...
caird coinheringaahin g's user avatar
19 votes
3 answers
388 views

A multiple of n in every base!

In November 2019, Alon Ran published a particularly lovely sequence in the OEIS, A329126: \$a(n)\$ is the lexicographically earliest string of digits which yields a multiple of \$n\$ when read in any ...
Peter Kagey's user avatar
  • 8,659
11 votes
13 answers
716 views

'Plane' the numbers in any base!

Inspired by this Numberphile video. What is planing? In order to 'plane' a sequence of digits, you need to: Identify the lengths of the 'runs' (adjacently repeated digits) in the sequence. Non-...
Geza Kerecsenyi's user avatar
32 votes
15 answers
2k views

Compute the generalised XOR

The goal of this challenge is to generalise the bitwise XOR function to other bases. Given two non-negative integers \$ x \$ and \$ y \$, and another integer \$ b \$ such that \$ b \geq 2 \$, write a ...
xavc's user avatar
  • 391
5 votes
12 answers
936 views

Base-ically Guard

Base: part 1 This is part 2, Strongly suggest you go try out the first one if you haven't tried it. Story As one of the solvers, You've managed to get to the door of the base heaven. In front of the ...
okie's user avatar
  • 1,807
8 votes
17 answers
1k views

Base-ically god

Story The god of base is opening heaven’s gate for mortals to join the base party. You, as one of the believers, want to follow their steps to ascend to heaven. But not everyone can get in. The god ...
okie's user avatar
  • 1,807
25 votes
33 answers
2k views

Count the trailing zeros

Given two positive integers \$n\$ and \$b\$, such that \$n > 2\$ and \$n > b > 1\$, count the trailing zeros when converting \$n\$ to base \$b\$. Your program should be able to handle any ...
caird coinheringaahin g's user avatar
11 votes
3 answers
357 views

Help me count the Omer

During the 49 days between Passover and Pentecost, Jewish liturgy provides four numerical problems that I've here phrased as code golf problems. Input/Arguments These four, in any order, and by any ...
Adám's user avatar
  • 29.9k
23 votes
27 answers
2k views

Based Palindromes

A palindromic number, as a refresher, is any number which reads the same forward as backwards. However, what about palindromes in other bases? Input Any integer b ...
Gio D's user avatar
  • 504
15 votes
12 answers
999 views

Compute the Redwolf Checksum™ of some data

I will preface this by saying that I made this for fun; I have absolutely no formal knowledge on cryptography or error correction. Do not use this algorithm in anything remotely important. I was kind ...
Rydwolf Programs's user avatar
22 votes
25 answers
1k views

Possible binaries sum

This challenge is inspired by the AoC 2020, Day 14 - Part II, created by Eric Wastl and his team, which asks to output the possible binary values from a bitmask. Let's say we've a bitmask like ...
vrintle's user avatar
  • 2,970
23 votes
27 answers
2k views

Perfect radicals

Given a positive integer number \$n\$ output its perfect radical. Definition A perfect radical \$r\$ of a positive integer \$n\$ is the lowest integer root of \$n\$ of any index \$i\$: $$r = \sqrt[i]{...
AZTECCO's user avatar
  • 10.7k
26 votes
17 answers
3k views

Convert negadecimal to decimal (and back)

Negadecimal, also known as base -10, is a non-standard positional numeral system. Take the number \$1337_{10}\$. In decimal, this has the value one thousand three hundred thirty seven, and can be ...
Rydwolf Programs's user avatar
24 votes
37 answers
2k views

Display the exponent from a binary floating point number as a decimal value

Had my software final exams recently, one of the last questions had me thinking for a while after the exam had finished. Background IEEE754 numbers are according to the below layout The exponent is ...
DarkAndromeda31's user avatar
18 votes
7 answers
727 views

Combinatorial Decomposition

In the body of this challenge, \$\begin{pmatrix}n\\k\end{pmatrix}\$ is used to represent the number of combinations of \$k\$ elements of \$n\$, also written as \$\frac{n!}{k!(n-k)!}\$ or \$n\mathrm{C}...
golf69's user avatar
  • 2,049
12 votes
8 answers
1k views

Scientific notation in Base-16

Input a scientific notation number (base 10), output scientific notation in base 16 (as defined below). Details In scientific notation, all non-zero numbers are written in the form $$ m \times 10^n $$ ...
tsh's user avatar
  • 34k
17 votes
11 answers
2k views

The Double-Castle Numbers™

Introduction A double-castle number™ is a positive integer number that has a pattern of $$\underbrace{a\cdots a}_{m\text{ }a\text{s}}b\underbrace{a\cdots a}_{m\text{ }a\text{s}}b\underbrace{a\...
Shieru Asakoto's user avatar
10 votes
2 answers
436 views

Inverse of Conway base 13 function in \$\mathbb{Q}\$

(The \$\mathbb{Q}\$ in the title means rational numbers.) Background Conway base 13 function is an example of a strongly Darboux function, a function that takes every real number on any open ...
Bubbler's user avatar
  • 73.8k
13 votes
9 answers
438 views

Minimal Rotate-Right-Double numbers in base n

Task For a given base \$n \ge 3\$, find the smallest positive integer \$m\$, when written in base \$n\$ and rotated right once, equals \$2m\$. The base-\$n\$ representation of \$m\$ cannot have ...
Bubbler's user avatar
  • 73.8k
19 votes
22 answers
4k views

Convert to and from Base 94

The challenge Make 2 programs which convert decimal to and from base 94, or a bidirectional program. Base 94? Base 94 is like any other base, but instead of 0 to 9 and letters, it uses ASCII ...
PkmnQ's user avatar
  • 2,693
9 votes
12 answers
389 views

Does base n have any Rotate-Left-Double numbers?

Task A Rotate-Left-Double number in base \$n\$ is a number \$m\$, when its base-\$n\$ digits are rotated left once, equals \$2m\$. The base-\$n\$ representation of \$m\$ cannot have leading zeros. ...
Bubbler's user avatar
  • 73.8k
30 votes
45 answers
7k views

Convert a 32 bit binary IPv4 address to its quad-dotted notation

Challenge Write a program or function that converts a 32 bit binary number to its quad-dotted decimal notation (often used for representing IPv4) Quad-dotted decimal A quad-dotted decimal is formed ...
mabel's user avatar
  • 1,619
16 votes
16 answers
1k views

Find the length of a number's "base-jumping" path

Consider a positive integer N written in base b. A sequence is generated from this number by finding the largest digit ...
Arcturus's user avatar
  • 7,349
31 votes
4 answers
4k views

How close are we, really?

Please note: this is a restricted-source challenge — see details below! Each natural number \$n\$ has 10 faces: its decimal representations in bases \$1\$ through to \$10\$. For example, the 10 faces ...
caird coinheringaahin g's user avatar
-1 votes
2 answers
284 views

Mirror, Mirror, on the wall. Who's the fairest of them all?

Well, you know it's Snow White, and the evil Queen is at it again. Will Snow White be saved? Will she fall asleep once again? Will the Prince find her? Challenge: Given an arbitrary number (>= 2) ...
Avi's user avatar
  • 281
44 votes
30 answers
9k views

French license plates

Sandbox French License Plates French license plates come in a sequential order, following a specific pattern of numbers and letters : AB-012-CD Challenge Write ...
Elcan's user avatar
  • 1,043
18 votes
19 answers
2k views

Simplification of numbers

How, you can’t remember the 6 or 7-digit phone number that appeared on the TV screen for a second?! Using the special technique described below, you will turn into a walking phonebook! Obviously, the ...
Ver Nick's user avatar
  • 607
-1 votes
11 answers
538 views

Convert alphanumeric (base-36) sentences into hexadecimal (base-16) sentences

I use "sentence" here loosely to mean "any sequence of words separated by spaces" and "words" to mean "sequences of alphanumeric (hexatrigesimal) characters unseparated by spaces". Conversion is from ...
DrQuarius's user avatar
  • 642
-2 votes
11 answers
379 views

Convert a number into "bracket" numerals

"Bracket" numerals are a type of 'numerals' I made up once, and thought would be a nice challenge here. Basically, you convert the input number into base 6, and then transliterate the ...
Ethan Slota's user avatar
-2 votes
15 answers
616 views

Find how "smooth" a number is based on binary

I haven't been on PP&CG for a while, so I thought I would post something! Your task is to find how "smooth" a natural number is. Your method is to: 1: Convert the number to binary 2: Find the ...
Ethan Slota's user avatar
1 vote
1 answer
242 views

Pumping quine radix

Inspired (you don't need to know them for this challenge) by the Pumping Lemma for various languages, I propose the following challenge: choose some basis \$B \geq 2\$ and an integer \$n \geq 0\$ ...
ბიმო's user avatar
  • 16.7k
23 votes
29 answers
2k views

Digital Sumorial

Given an input n, write a program or function that outputs/returns the sum of the digital sums of n for all the bases 1 to ...
Oliver's user avatar
  • 7,842