Questions tagged [binary]
For challenges about binary, or the base 2 number system.
232
questions
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:
...
86
votes
11
answers
16k
views
How on earth did llhuii output the Evil Numbers in 42 bytes of Python?
This is a tips question for golfing in Python concerning the Evil Numbers question on Anarchy Golf.
An number is evil if its binary expansion has an even number of 1's. The challenge is to print the ...
77
votes
62
answers
8k
views
Is it a Cyclops number? "Nobody" knows!
Task:
Given an integer input, figure out whether or not it is a Cyclops Number.
What is a Cyclops number, you may ask? Well, it's a number whose binary representation only has one ...
74
votes
97
answers
7k
views
Is the number binary-heavy?
An integer is binary-heavy if its binary representation contains more 1s than 0s while ignoring leading zeroes. For example 1 is ...
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 ...
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 ...
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
...
51
votes
31
answers
6k
views
prOGraMMIng PuZZleS & cOde ____
Input
A non-empty encoded string consisting of printable ASCII characters (in the range 32-126), where some missing letters have been replaced with _.
Output
A ...
49
votes
51
answers
5k
views
Bit run rundown
Given an integer n > 0, output the length of the longest contiguous sequence of 0 or 1 in ...
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
...
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 ...
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 ...
43
votes
25
answers
3k
views
Let's study Neil numbers
Congratulations to Neil for hitting 100k rep! As a tribute, we are going to study 'Neil numbers'.
Neil's user ID is 17602 and there's something special about the binary representation of this number:
...
43
votes
17
answers
2k
views
Generate the Temple Skyline Sequence
Consider the following process:
Take some non-negative integer N.
e.g. N = 571
Express it in binary with no leading zeroes. (Zero itself is the only exception, ...
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 ...
41
votes
11
answers
4k
views
Find a binary needle in a decimal haystack
The challenge
You're given:
a non-empty, unsorted list h of positive integers (the haystack)
a positive integer n (the needle)
Your task is to return the list of all unique decimal concatenations ...
40
votes
32
answers
4k
views
Output numbers up to 2^n-1, "sorted"
Take a positive integer n as input, and output (some of the) decimal numbers that can be created using n bits, ordered in the following way:
First list all the numbers that can be created with only ...
37
votes
63
answers
8k
views
Sum of Powers of 2
The Challenge
Given an integer input x where 1 <= x <= 255, return the results of powers of two that when summed give <...
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:
...
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 ...
36
votes
54
answers
5k
views
The first n numbers without consecutive equal binary digits
The sequence contains the decimal representation of the binary numbers of the form: 10101..., where the n-th term has n bits.
The sequence is probably easiest to ...
36
votes
34
answers
5k
views
Create a binary wall
Given an array of positive integers in base 10, where n > 0, output their representation of a binary wall.
How does this work?
Convert each number to it's ...
36
votes
12
answers
3k
views
Store eight bits on a punched card
A little while back, data was frequently stored on punched card. A typical card would have 80 columns of 12 possible 'punch' positions. A plethora of encodings was used, each for their own specific ...
36
votes
11
answers
3k
views
Encode an integer
Given positive integer n > 2. We convert it to an array as follows:
If it is equal to 2 return an empty array
Otherwise ...
35
votes
69
answers
9k
views
Convert a string of binary characters to the ASCII equivalents
Take a string of binary characters separated by a space, and convert it to an ASCII string.
For example...
...
35
votes
36
answers
5k
views
Binary Fibonacci
Challenge
You need to generate a program or function that takes in a positive integer N, calculates the first N terms of the Fibonacci sequence in binary, concatenates it into a single binary number, ...
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 ...
34
votes
32
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) ...
34
votes
36
answers
5k
views
Calculate the longest series of 1's in an integer's binary value
Goal
Given a non-negative integer, create a function that returns the starting position of number of largest consecutive 1's in that integer's binary value.
When given an input ...
33
votes
79
answers
17k
views
Clearing the most significant bit from an integer
Input
The input is a single positive integer n
Output
The output isn with its most significant bit set to ...
33
votes
15
answers
5k
views
Let's play Mölkky!
Mölkky
Mölkky is a Finnish throwing game. The players use a wooden pin (also called "mölkky") to try to knock over wooden pins of almost similar dimensions with the throwing pin, marked with ...
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 ...
32
votes
49
answers
6k
views
Is that number a Two Bit Number™?
Let's start by defining a Two Bit Number™:
It is a positive integer
When expressed as a binary string it has exactly 2 true bits OR
When expressed as a decimal number, it has exactly 2 of the numeral ...
32
votes
77
answers
12k
views
Count the number of ones in an unsigned 16-bit integer
Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer.
For example, if the input is 1337, then the result is ...
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 ...
32
votes
31
answers
3k
views
Collatz Encoding
The Collatz Conjecture
The famous Collatz Conjecture (which we will assume to be true for the challenge) defines a sequence for each natural number, and hypothesizes that every such sequence will ...
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 ...
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 ...
32
votes
19
answers
3k
views
Decode USB packets
Inspired by this video by Ben Eater. This challenge forms a pair with Encode USB packets.
The USB 2.0 protocol uses, at a low level, a line code called non-return-to-zero encoding (specifically, a ...
32
votes
7
answers
2k
views
Finite tilings in one dimension
The purpose of this challenge is to determine if a collection of one-dimensonal pieces can be tiled to form a finite continuous chunk.
A piece is a non-empty, finite sequence of zeros and ones that ...
31
votes
70
answers
4k
views
Number to Binary
It seems we've managed to go all this time without a plain vanilla Number-To-Binary challenge! Whilst this will inevitably be only one element in many languages, it should put a few esolangs through ...
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.
...
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 ...
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 ...
30
votes
25
answers
3k
views
Palindromic numbers with a binary twist
Warning : this is NOT a "hey, let's draw a cake in ASCII-art" challenge! Please keep reading ;)
Some time ago it was my birthday, I'm 33 now.
So there is this awkward social tradition consisting in ...
29
votes
26
answers
5k
views
Fizz Buzz to Text
Introduction
I don't particularly know where the fizz buzz trend came from. It might just be a meme or something, but it is somewhat popular.
Challenge
Your job today is to convert Fizz Buzz into ...
29
votes
40
answers
4k
views
The dragon Curve sequence
The dragon curve sequence (or the regular paper folding sequence) is a binary sequence. a(n) is given by negation of the bit left of the least significant 1 of <...
29
votes
31
answers
2k
views
Generate Parity bits
Given a binary message, and the number of parity bits, generate the associated parity bits.
A parity bit is a simple form of error detection. It's generated by counting the number of ...
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\$ ...
29
votes
20
answers
3k
views
Simple Boolean Algebra Calculator
Background
Boolean Algebra concerns representing values with letters and simplifying expressions. The following is a chart for the standard notation used:
Above is what actual boolean algebra looks ...