Questions tagged [binary]

For challenges about binary, or the base 2 number system.

Filter by
Sorted by
Tagged with
26 votes
26 answers
2k views

Digital Hardness of Integers

To find the digital hardness of an integer, take its binary representation, and count the number of times both a leading and trailing 1 can be removed until it ...
FlipTack's user avatar
  • 14.6k
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
  • 955
47 votes
28 answers
4k views

A bit, a nibble or byte?

Inspired by this challenge Given an integer in the range 0 <= n < 2**64, output the minimum sized container it can fit in out of bit: 1 nibble: 4 byte: 8 ...
Blue's user avatar
  • 28.5k
55 votes
73 answers
8k views

In how many bits do I fit

For any positive 32-bit integer (1 ≤ n ≤ 0xFFFFFFFF) output the number of bits needed to represent that integer. Test cases ...
Bassdrop Cumberwubwubwub's user avatar
16 votes
1 answer
758 views

Every prime bit must alternate

A program is bit primed if bits in prime positions must alternate between zero and one, starting with one. For example, this is a template for a bit primed program with [0..47] bits. ...
noɥʇʎԀʎzɐɹƆ's user avatar
16 votes
9 answers
761 views

Sloping Binary Numbers

Given an integer n, output the first n sloping binary numbers, either 0- or 1-indexed. They are called this because of how they ...
mbomb007's user avatar
  • 23.3k
21 votes
28 answers
2k views

The Baum-Sweet Sequence

The Baum-Sweet Sequence (A086747 with a Twist) Take in a positive integer n and print the integers from 1 to n for which the Baum-Sweet sequence returns true. The ...
Magic Octopus Urn's user avatar
45 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
25 answers
3k views

Complex Binary Numbers

Let's create a simple, surjective mapping from positive integers to Gaussian integers, which are complex numbers where the real and imaginary parts are integers. Given a positive integer, for example ...
Calvin's Hobbies's user avatar
27 votes
21 answers
1k views

Primenary Strings

A Primenary (binary-prime) string is one which, when written as a binary grid, every row and column has a prime total. That's quite a vague explanation, so let's break it down with a worked example......
FlipTack's user avatar
  • 14.6k
16 votes
5 answers
2k views

Binary Convolution

A binary convolution is described by a number M, and is applied to a number N. For each bit in the binary representation of <...
user avatar
19 votes
29 answers
2k views

Binary Countdown Length

inspired by Count down from infinity Given a non-negative integer N, output the number of repetitions of the following steps it takes to reach 0: Convert ...
user avatar
9 votes
11 answers
880 views

Ordered list of binary sequences of multiple dimensions

Given a positive integer n, output the 2^n binary sequences of length n sorted in the ...
defarm's user avatar
  • 117
1 vote
2 answers
285 views

Chained Binary Operations

Chained Binary Operations Here's a challenge involving truth tables and binary operations. For this specific challenge, your task is to use the following table of operations: To create a function ...
Magic Octopus Urn's user avatar
101 votes
23 answers
17k views

Where's the 0xBEEF?

This challenge was inspired by this Wendy's commercial from 1984. Illustration by T S Rogers Your task is to find a hexadecimal 0xBEEF on a binary bun. The 'beef' consists of the following pattern: ...
Arnauld's user avatar
  • 189k
10 votes
9 answers
948 views

Super Folding Numbers

We have already defined a folding number here. But now we are going to define a Super Folding Number. A Super Folding number is a number that if folded enough times it will eventually reach one less ...
Wheat Wizard's user avatar
  • 96.5k
37 votes
27 answers
3k views

Folding Numbers

Given a number determine if it is a folding number. A folding number is a number such that if you take it binary representation and "fold" it in half, That is take the result of XNOR ...
Wheat Wizard's user avatar
  • 96.5k
41 votes
14 answers
5k views

Incrementing Gray Codes

Introduction A Gray Code is an alternative to binary representation in which a number is incremented by toggling only one bit, rather than a variable amount of bits. Here are some gray codes along ...
Patrick Roberts's user avatar
59 votes
27 answers
14k views

i love yOu i lOve you i love yOu!

XKCD #99, with the title "Binary Heart" shows a simple image of ones and zeros, with some digits colored red. The red heart is visible to the naked eye, but the message hidden in the binary sequence ...
Stewie Griffin's user avatar
9 votes
20 answers
1k views

String and ASCII [duplicate]

The Challenge Given a non-empty string containing only lowercase or uppercase letters and no spaces: Sum up the ASCII values for each character instance in the input string. The sum will be ...
Ajay's user avatar
  • 623
33 votes
6 answers
3k views

Telegraphy Golf: Decode Baudot Code

Background In 1870 Émile Baudot invented Baudot Code, a fixed-length character encoding for telegraphy. He designed the code to be entered from a manual keyboard with just five keys; two operated with ...
Jordan's user avatar
  • 9,726
12 votes
19 answers
1k views

All Binary Combinations to Decimal

Disclaimer This question is not a duplicate of this question. I'm not counting specific digits, as we already have those set in the initial parameters. This question is focusing on the decimal ...
Eliseo D'Annunzio's user avatar
10 votes
11 answers
2k views

Given an integer, compute its Levenshtein code

Disclaimer: Levenshtein coding is completely unrelated to the Levenshtein edit distance metric. <Insert long story about why Levenshtein codes need to be calculated here.> The code Levenshtein ...
LegionMammal978's user avatar
66 votes
11 answers
4k views

Only Even Bytes

The scenario Lately you have been noticing some strange behavior with your favorite text editor. At first it seemed that it was ignoring random characters in your code when writing to disk. After a ...
Wheat Wizard's user avatar
  • 96.5k
17 votes
2 answers
390 views

Given a truth table, output a Stackylogic program that satisfies it

Stackylogic is a programming language I made up in a previous challenge: Run Stackylogic. Read that post for full details and examples, but here is how it works paraphrased: Stackylogic takes ...
Calvin's Hobbies's user avatar
46 votes
11 answers
2k views

Run Stackylogic

Stackylogic is a logic-based programming language I made up that take in 0's and 1's for input and outputs a single ...
Calvin's Hobbies's user avatar
29 votes
30 answers
4k views

Bit-Reversal Permutations

Your goal is to create a function or a program to reverse the bits in a range of integers given an integer \$n\$. In other words, you want to find the bit-reversal permutation of a range of \$2^n\$ ...
miles's user avatar
  • 16.9k
25 votes
23 answers
2k views

Swap bits with their neighbours

Task description Given an integer, swap its (2k–1)-th and 2k-th least significant bits for all integers k > 0. This is sequence A057300 in the OEIS. (The number is assumed to have “...
Lynn's user avatar
  • 68.1k
15 votes
11 answers
1k views

What's the Binary Time?

What's the Binary Time? Everybody knows what the normal time is. It's up there in the top-right (or wherever you put it) of your screen. But a question people rarely seem to ask themselves is this: ...
user avatar
31 votes
44 answers
3k views

Mean bits: an average challenge

Given an integer N >= 1, output the mean number of bits in an integer from 0 to N - 1 Specification The output can be calculated as the sum of the number of bits in the binary representation of each ...
trichoplax is on Codidact now'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
16 votes
11 answers
1k views

Sum of Binary Substrings

This challenge is simple, given a decimal number, convert to binary, and calculate the sum of the sub-strings of the binary number, whose length is shorter than the original number. Here is an example:...
GamrCorps's user avatar
  • 7,502
19 votes
12 answers
4k views

When will I have a binary car?

I noticed that my car's odometer was at 101101 when I got to work today. Which is a cool number because it's binary (and a palindrome, but that's not important). Now, I want to know when the next time ...
Morgan Thrapp's user avatar
6 votes
1 answer
296 views

Model a probability table using 15-bit fixed probabilities

A histogram is an array of integers that counts the number of times a symbol occurs. For example, for the string "aaabbbabbdebabbbebebdbaaabbabaaaaeebeaabaaba" a ...
orlp's user avatar
  • 39k
8 votes
4 answers
513 views

Shortest binary number in range

Given two arbitrarily precise decimal numbers 0 ≤ x < y ≤ 1, compute the shortest (in digits) binary number b such that x ≤ b < y. Output the binary digits of b after the binary ...
orlp's user avatar
  • 39k
12 votes
18 answers
1k views

Preparing a multiple choice test

Introduction Note: this is not some kind of method to encourage cheating. As Cᴏɴᴏʀ O'Bʀɪᴇɴ already said, studying is the best solution for passing a test :3. Consider the following answers to the ...
Adnan's user avatar
  • 44.3k
29 votes
6 answers
4k views

1+1 = 10, 1+2 = 3

Write a function or program than can do simple arithmetic (addition, subtraction, multiplication and division) in both base 10 and base 2. The function will take a mathematical expression as input, ...
Stewie Griffin's user avatar
10 votes
3 answers
443 views

I-Ching pair binary computer

Introduction I Ching is an ancient divination text and the oldest of the Chinese classics. It uses a type of divination called cleromancy, which produces apparently random numbers. The basic unit of ...
F. Hauri  - Give Up GitHub's user avatar
3 votes
5 answers
939 views

Binary Run-Length Encoding [duplicate]

Overview Run-length encoding — sequences in which the same data value occurs in many consecutive data elements are stored as a single data value and count When using run-length encoding: ...
Zach Gates's user avatar
  • 6,660
23 votes
25 answers
2k views

Compute the Binary Sierpinski Triangle Sequence

The Binary Sierpinski Triangle sequence is the sequence of numbers whose binary representations give the rows of the Binary Sierpinski Triangle, which is given by starting with a 1 in an infinite row ...
quintopia's user avatar
  • 4,087
26 votes
36 answers
4k views

Write out the Thue-Morse sequence

There's quite a few challenges on this site that ask you to print out a sequence, and this is no exception. (The following explanation of the sequence for this challenge assumes the symbols in the ...
Sherlock9's user avatar
  • 12.2k
32 votes
40 answers
3k views

Parenthifiable Binary Numbers

If you express some positive integer in binary with no leading zeros and replace every 1 with a ( and every ...
Calvin's Hobbies's user avatar
20 votes
17 answers
2k 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
24 votes
19 answers
1k views

Counting +1 primes

Define that the natural number p is a +1 prime of the natural number n if p is a prime number and the standard binary representation (i.e., without leading zeroes) of p can be obtained by adding (i.e.,...
Dennis's user avatar
  • 210k
27 votes
31 answers
3k views

Reverse and Invert a String

Reverse and Invert a String Challenge In this challenge. You'll be writing a program which will output or return the input, reversed and inverted. First, each character should be converted to its ...
Downgoat's user avatar
  • 28.9k
6 votes
3 answers
626 views

Symmetric boolean functions as Zhegalkin polynomials

Let \$\mathbb{B} = \mathbb{Z}_2 = \{0, 1\}\$ be the set of booleans. A symmetric boolean function in \$n\$ arguments is a function \$f_S : \mathbb{B}^n \to \mathbb{B}\$ that checks if the number of ...
FUZxxl's user avatar
  • 10.1k
32 votes
23 answers
4k views

Biplex: an important useless operator

Input A list of between 1 and 255 positive integers (inclusive), each in the range 1 to 232 - 1 (inclusive). Your input format does not need to be identical to the test cases. Input without leading ...
trichoplax is on Codidact now's user avatar
31 votes
33 answers
4k views

Numbers with multiple runs of ones

Task Find the set of numbers such that the binary representation contains two or more runs of 1 separated by at least one 0. ...
user avatar
19 votes
2 answers
942 views

Koopa Shell Sequence

In various Super Mario games green and red Koopa Troopa shells can slide frictionlessly on flat surfaces and destroy brick blocks that are in their way. When a shell hits a brick block the block ...
Calvin's Hobbies's user avatar
10 votes
4 answers
212 views

Counting cycles in a folding and squashing process

In chaos theory, the horseshoe map is an example of how chaos arises in a simple process of folding and squashing. It goes like this: take an imaginary piece of dough, fold it, and finally squash it ...
agtoever's user avatar
  • 2,891