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

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
16 votes
9 answers
2k views

Base Conversion With Strings

Introduction We've have a few base conversion challenges here in the past, but not many designed to tackle arbitrary length numbers (that is to say, numbers that are long enough that they overflow the ...
Mwr247's user avatar
  • 3,572
46 votes
84 answers
9k views

Binary to decimal converter

Binary to decimal converter As far as I can see, we don't have a simple binary to decimal conversion challenge. Write a program or function that takes a positive binary integer and outputs its ...
Stewie Griffin's user avatar
35 votes
20 answers
9k views

Balanced Ternary Converter

Credits for the challenge idea go to @AndrewPiliser. His original proposal in the sandbox was abandoned and since he has not been active here for several months, I have taken over the challenge. ...
user avatar
26 votes
8 answers
2k views

All your bijective base are belong to us

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 to b. Unlike its non-bijective ...
Dennis's user avatar
  • 210k
13 votes
7 answers
2k views

Mixed Base Conversion

Background Most people on here should be familiar with several base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, the number 1234516 would represent ...
Martin Ender's user avatar
29 votes
26 answers
3k views

Find the next 1-sparse binary number

A positive integer N is K-sparse if there are at least K 0s between any two consecutive 1s in its binary representation. So, the number 1010101 is 1-sparse whereas 101101 is not. Your task is to ...
articuno's user avatar
  • 391
24 votes
32 answers
3k views

Convert a number to Hexadecimal

Challenge Here's a simple one. Write a function or program when given a number in base 10 as input, it will return or print that number's value in Hexadecimal. Examples ...
Random Guy's user avatar
14 votes
22 answers
1k views

Determine if an integer is a palindrome in a given radix (base)

Write a program that reads from stdin two integers, each newline terminated, hereafter called "number" and "radix", and: Prints any fixed message you want if the number is a palindrome in that radix (...
durron597's user avatar
  • 4,810
33 votes
2 answers
2k views

Standardise a Phinary Number

Background Most people on here should be familiar with a few integer base systems: decimal, binary, hexadecimal, octal. E.g. in the hexadecimal system, a number \$abc.de_{16}\$ would represent $$a\...
Martin Ender's user avatar
29 votes
18 answers
11k views

Convert to and from the factorial number system

The Factorial Number System, also called factoradic, is a mixed radix numeral system. The factorials determine the place value of a number. In this system, the right most digit can be either 0 or 1, ...
Volatility's user avatar
  • 3,374
25 votes
11 answers
2k views

Determine the Base where a Given Equation is True

Given 3 integers, determine the lowest possible base for the first two integers to multiply into the third. If you think of the Answer to the Ultimate Question of Life, The Universe, and Everything, 6 ...
erdekhayser's user avatar
25 votes
18 answers
2k views

A multiplication table for the Cheela

The Cheela (from the book Dragon's Egg by Robert L. Forward) are creatures that live on the surface of a neutron star. Their body is flat and circular with twelve eyes on the perimeter, so they ...
Luis Mendo's user avatar
  • 105k
22 votes
17 answers
1k views

All your base palindromic belong to us

Generate the sequence number of bases in which n is a palindrome (OEIS A126071). Specifically, the sequence is defined as follows: given a number ...
Luis Mendo's user avatar
  • 105k
16 votes
10 answers
2k views

Brainf**k to Unary and Back

A language that is very useful in restricted source and other such challenges is Unary, a brainfuck derivative in which programs are written in with only one character. Your job is to write a program ...
Maltysen's user avatar
  • 25.7k
68 votes
27 answers
15k views

xkcd-Style Page Numbering

Randall Munroe's book "xkcd, volume 0" uses a rather odd number system for the page numbers. The first few page numbers are ...
Martin Ender's user avatar
42 votes
51 answers
5k views

Numbers that are actually letters

Given a non-negative integer input, write a program that converts the number to hexadecimal and returns a truthy value if the hexadecimal form of the number contains only the characters ...
Arcturus's user avatar
  • 7,387
24 votes
33 answers
4k views

ASCII art uncompression from a base-n number

This is inspired by an 05AB1E answer by Magic Octupus Urn. Given two arguments, a positive integer and a string/list of characters: Translate the number to base-n, where n is the length of the ...
Jo King's user avatar
  • 47.2k
21 votes
13 answers
1k views

The Binary Square Diagonal Sequence

The binary-square-diagonal-sequence is constructed as follows: Take the sequence of positive natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ... Convert each number to ...
Laikoni's user avatar
  • 26.2k
21 votes
12 answers
2k views

ASCII Maya Numbers

Write a program or function which, given a positive integer as input, outputs the representation of that integer in Maya numerals. Maya numerals Maya numerals is a vigesimal system (base 20) using ...
Fatalize's user avatar
  • 38.7k
20 votes
27 answers
1k views

Decompose a number!

Your task is to decompose a number using the format below. This is similar to base conversion, except that instead of listing the digits in the base, you list the <...
Leaky Nun's user avatar
  • 49.7k
20 votes
20 answers
4k views

Lowest-Base Palindrome

Given a number \$n\$, write a program that finds the smallest base \$b ≥ 2\$ such that \$n\$ is a palindrome in base \$b\$. For example, an input of \$28\$ should return the base \$3\$ since \$28_{10} ...
user avatar
20 votes
14 answers
1k views

Output N in base -10

Challenge: In the programming language of your choice, accept an integer as input in base 10, and output it in the negadecimal notation, which is also known as base -10 Example algorithm: This is ...
Offtkp's user avatar
  • 3,062
18 votes
8 answers
667 views

Convert between balanced bases!

Balanced bases: Balanced bases are essentially the same as normal bases, except that digits can be positive or negative, while in normal bases digits can only be positive. From here on, balanced ...
clismique's user avatar
  • 6,980
17 votes
12 answers
2k views

Convert from binary to negabinary

Given a binary integer inclusively between 0 and 1111111111111111 (i.e. a 16-bit unsigned integer) as input, output the same ...
Peter Olson's user avatar
  • 7,732
13 votes
13 answers
5k views

Convert a bytes array to base64

Your mission is to write a function/program that converts an array of bytes (i.e: an array of integers from 0 to 255), to base64. Using built-in base64 encoders is not allowed. The required base64 ...
xem's user avatar
  • 5,825
9 votes
2 answers
549 views

Hereditary Base Change

Background In this challenge, a base-b representation of an integer n is an expression of n ...
Zgarb's user avatar
  • 42.7k
8 votes
8 answers
859 views

Extension of the Game of Sevens

Introduction Output all the numbers in specific base that would appear in an adapted version of the game of seven. Challenge Your task is to output all the numbers in a given base in a given range, ...
Weijun Zhou's user avatar
  • 3,637
7 votes
18 answers
2k views

Minimum base to count to a string

The Challenge Input: alphanumeric string. You can assume that the string will only contain the characters [0-9A-Z]. This can come from a parameter, command line, or STDIN. Digits are always before ...
tfitzger's user avatar
  • 979
46 votes
23 answers
9k views

Count down from "Infinity"

Seems like an impossible task right? Well, it's actually not that hard. If we write the word Infinity as 8-bit binary ASCII code, we'll get: ...
Stewie Griffin's user avatar
43 votes
26 answers
6k views

The best base is 10... Let's reach it!

Input: A positive integer n consisting of digits in the range 0-9. Challenge: If d is the highest digit in the integer, assume the base of the number is d+1. E.g. if the integer is 1256 then you ...
Stewie Griffin's user avatar
39 votes
34 answers
3k views

Mark My Mail! - ASCII Barcodes

4-state barcodes Many postal services (Royal Mail UK, Canada Post, US Mail, etc) use a 4-state barcode to encode information about their mail. Rendered in ASCII, it may look something like this: | ...
FlipTack's user avatar
  • 14.7k
37 votes
49 answers
10k views

What is the reverse (binary) bit number?

So you are given a POSITIVE base 10 (decimal) number. Your job is to reverse the binary digits and return that base 10 number. Examples: ...
Joseph's user avatar
  • 953
37 votes
39 answers
4k views

16-bit binary grid

Given any unsigned 16 bit integer, convert its decimal form (i.e., base-10) number into a 4x4 ASCII grid of its bits, with the most-significant bit (MSB) at the top left, least-significant bit (LSB) ...
type_outcast's user avatar
32 votes
32 answers
2k views

Decompose binary into alternating subsequences

This was inspired by Problem 13 - Non-Repeating Binary of HP CodeWars' recent competition. Let's take a random decimal number, say 727429805944311 and look at ...
El'endia Starman's user avatar
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
29 votes
20 answers
3k views

Is this a three-digit number ending in one?

Given a nonnegative integer, return whether it is a three digit number ending in one, in any consistent integer base. In other words, the number needs to be represented in base-N, N being an integer ...
HAEM's user avatar
  • 671
27 votes
3 answers
3k views

Residue Number System

In the vein of large number challenges I thought this one might be interesting. In this challenge, we will be using the Residue Number System (RNS) to perform addition, subtraction, and ...
Liam's user avatar
  • 3,215
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
25 votes
14 answers
1k views

Find the nth Fibohexaprime

The challenge this time is to find the nth Fibohexaprime. The definition of a Fibohexaprime is as following: We first observe a list with Fibonacci numbers: ...
Adnan's user avatar
  • 44.4k
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,365
24 votes
14 answers
2k views

ASCII Character Jumble

Write a program that takes as its input a string consisting of printable characters (ASCII 20-7E) and an integer n in [2,16] and performs the following modification ...
Arcturus's user avatar
  • 7,387
23 votes
23 answers
3k views

Simplify binary

Challenge Given a binary number as input through any means, "simplify" the number using a full program or a function. Input [binary] ...
The_Basset_Hound's user avatar
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.8k
23 votes
3 answers
438 views

Big base, small digits

The J language has a very silly syntax for specifying constants. I want to focus on one cool feature in particular: the ability to write in arbitrary bases. If you write ...
algorithmshark's user avatar
22 votes
8 answers
1k views

Find the polynomial

We know that f is a polynomial with non-negative integer coefficients. Given f(1) and f(1+f(1)) return f. You may output f as a list of coefficients, an ASCII formatted polynomial, or similar. ...
orlp's user avatar
  • 39.1k
20 votes
30 answers
3k 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
20 votes
8 answers
2k views

Primes in Different Bases

Challenge: You are given a base 10 number. For each base from 10 counting down to base 2: Take the original input number as a base 10 string, and remove any digits of the number which are invalid ...
poi830's user avatar
  • 1,303
18 votes
15 answers
1k views

Non-palindromic numbers

A strictly non-palindromic number N is a number that isn't a palindrome in any base (in bases 2 to N-2). These numbers are listed on OEIS For example, the number 19...
Nathan Merrill'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.7k
13 votes
40 answers
3k 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
  • 7,123