Questions tagged [binary]
For challenges about binary, or the base 2 number system.
232
questions
18
votes
34
answers
2k
views
Rudin-Shapiro sequence
The Rudin-Shapiro sequence is a sequence of \$1\$s and \$-1\$s defined as follows: \$r_n = (-1)^{u_n}\$, where \$u_n\$ is the number of occurrences of (possibly overlapping) \$11\$ in the binary ...
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 ...
13
votes
23
answers
2k
views
Alternating bit smearing
Introduction
This challenge requires you to set the trailing zeros of an integers binary representation to 010101…, this is best explained with an example:
Given ...
27
votes
27
answers
2k
views
Measure the lengths of binary patterns
Let's consider the sequence of the binary representation of positive integers (without any leading zero):
...
25
votes
14
answers
2k
views
Emanresu numbers
My userid is 100664. In binary this is 11000100100111000.
An interesting property of this number is that it can be created entirely by concatenating strings which ...
18
votes
22
answers
2k
views
Find the substring with the most 1's in a sequence
Introduction
I want to find the substring with the most 1's in a sequence of 0's and 1's.
...
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 ...
20
votes
23
answers
2k
views
Diagonal Binary Sequence
Challenge:
Given a positive number \$n\$, convert it to binary, and output a sequence where all 1s form a top-left to bottom-right diagonal line, including a ...
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 ...
15
votes
14
answers
3k
views
I want 8 bits for every character!
This is the reverse of this challenge.
Given an encoded list of codepoints and the characters used to encode it, you need to decompress it to its original string.
For example, given the encoded list <...
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 ...
2
votes
2
answers
204
views
Binary expansion and partition numbers [closed]
Not sure if it's correct to ask such a question on this site, but let's try.
Let a(n) be a sequence of positive integer such that a(1) = 1. To reproduce the sequence a(n) through itself, use the ...
23
votes
17
answers
4k
views
Who needs 8 bits for one character?
Given a string and the characters used to encode it, you need to compress the string by only using as many bits as each character needs. You will return the character codes for each character needed ...
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 ...
22
votes
62
answers
4k
views
count ones in range
Challenge :
Count the number of ones 1 in the binary representation of all number between a range.
Input :
Two non-decimal positive integers
Output :
The sum of ...
13
votes
14
answers
1k
views
CGAC2022 Day 10: Help Santa sort presents!
Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Santa likes to sort his presents in a special way. He keeps "uninterleaving" the pile of presents into ...
16
votes
5
answers
591
views
Prefix code generator
In this challenge, we consider an encoding from positive integers (up to a limit) to binary sequences. Some examples:
...
11
votes
33
answers
1k
views
Convert the decimal digits of a string's Unicode codepoints to binary, reinterpret as decimal, and take the sum
Yeah... it's confusing. Let me explain it a little better:
With a string, get the unicode code points of each letter
Let's use "Hello World!".
The code ...
26
votes
33
answers
2k
views
Primes with prime bit-counts
Task
Find all the non-negative integers up to and including a given non-zero positive integer n, that are prime and the count of 1's and ...
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.
...
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 ...
12
votes
39
answers
3k
views
Hexadecimal -> Binary Art
Take a list of 2-digit hexadecimal numbers as input, and output the binary value, replacing each 1 with an 'X', and each 0 with a space.
For example
Input = ...
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 <...
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 ...
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 ...
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 ...
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 ...
14
votes
2
answers
1k
views
Count how many distance sequences are far from all others
The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.
Let P be a binary string of ...
1
vote
1
answer
158
views
Start a program so that /proc/self/cmdline contains a binary representation of the input number
I am sorry for the very long description. But i think some information of how /proc/self/cmdline works and how it can be used to get a integer input was necessary.
...
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 ...
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:
...
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 ...
21
votes
20
answers
2k
views
Cut along the lines
In this challenge you will take as input a non-empty list of binary values (these can be booleans or integers on the range 0-1), you should output all the ways to partition the list into non-empty ...
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 ...
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 ...
1
vote
0
answers
140
views
making a binary string palindrome using xor operations [closed]
Problem
You are given a binary string A of length N.
You can perform the following type of operation on the string A:
Choose two different indices \$i\$ and \$j\$ (\$1 \le i\$, \$j \le N\$)
Change \$...
26
votes
65
answers
6k
views
String to Binary
This is a code golf challenge. Just like the title says, write a program to covert a string of ascii characters into binary.
For example:
"Hello World!"
should ...
2
votes
11
answers
8k
views
compute number of 1 bits in a binary representation of a number
The goal is to write a program that returns number of 1 bits in a given number.
Examples
5 -> 2
1254 -> 6
56465 -> 8
Winner
The winning ...
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...
...
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
...
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 ...
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 ...
12
votes
15
answers
2k
views
Quine outputs itself in binary
Your task, if you wish to accept it, is to write a program that outputs its own source code in the binary UTF-8 representation.
Rules
The source must be at least 1 byte long.
Your program must not ...
21
votes
13
answers
2k
views
Minkowski's ?(x) for rational x
Here is Minkowski's question mark function:
It is a strictly increasing and continuous function from the reals to themselves that, among other unusual properties, maps rational numbers to dyadic ...
21
votes
36
answers
6k
views
Binary representation of a number is palindrome or not?
Write a full program to find whether the binary representation of a number is palindrome or not?
Sample Input
5
Sample Output
YES
Print ...
15
votes
50
answers
6k
views
Print the amount of ones in a binary number without using bitwise operators
Description
Given a number, print the amount of 1s it has in binary representation.
Input
A number >= 0 in base 10 that ...
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, ...
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 ...
8
votes
3
answers
355
views
Injectively saturate bit strings
It can be easily proven using Hall's marriage theorem that given fixed \$n\$ and \$k<n/2\$, there is an injective (one-to-one) function from all \$n\$-bit strings with \$k\$ ones to \$n\$-bit ...
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
...