2022 Developer Survey is open! Take survey.

Questions tagged [binary]

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

Filter by
Sorted by
Tagged with
13 votes
10 answers
2k 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 <...
user avatar
  • 4,076
20 votes
13 answers
2k views

Bitwise XOR of floats

This is different from Floating Point XOR, and more in the spirit of a comment by R.. GitHub STOP HELPING ICE on that challenge, but I thought of this idea independently. Generalized XOR The bitwise ...
user avatar
21 votes
16 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 ...
user avatar
  • 4,076
29 votes
28 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 ...
user avatar
15 votes
24 answers
2k views

The Binary Eyes

A binary eye is an odd set of digits, with all of its digits except the center one set to 1 or 0, and the center one set to the opposite of the others. Thus, there are two binary eyes for a given odd ...
user avatar
  • 457
14 votes
17 answers
1k views

The interstice of two binary numbers

Given two integers, compute the two numbers that come from the blending the bits of the binary numbers of equal length(same number of digits, a number with less digits has zeros added), one after the ...
user avatar
  • 457
19 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 ...
user avatar
  • 1,260
19 votes
10 answers
2k views

1 bit, 2 bits, 3 bits, …

Given a positive integer \$n\$, your task is to find out the number of partitions \$a_1+a_2+\dots+a_k=n\$ where each \$a_j\$ has exactly \$j\$ bits set. For instance, there are \$6\$ such partitions ...
user avatar
  • 166k
10 votes
32 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 ...
user avatar
1 vote
0 answers
119 views

Binary with 0's only [closed]

The input message consists of ASCII characters The encoded output message consists of blocks of 0 A block is separated from another block by a space Two consecutive blocks are used to produce a series ...
user avatar
  • 3,031
8 votes
14 answers
699 views

Get all binary between a binary string and its reverse

Your Challenge is to take a binary string as input and get all binary numbers between itself and the reverse of its string representation (the reverse may be less than or greater than the original ...
user avatar
16 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^...
user avatar
  • 18.5k
17 votes
11 answers
2k views

Binary triangle A141727

Challenge Generate the 2D sequence of bits of A141727. (Allowed I/O methods explained at the bottom.) ...
user avatar
  • 62.1k
14 votes
12 answers
1k views

Nega-Zeckendorf representation

Background Zeckendorf representation is a numeral system where each digit has the value of Fibonacci numbers (1, 2, 3, 5, 8, 13, ...) and no two consecutive digits can be 1. Nega-Zeckendorf ...
user avatar
  • 62.1k
13 votes
9 answers
676 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, -...
user avatar
24 votes
13 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 ...
user avatar
  • 27.3k
18 votes
14 answers
1k views

Encode USB packets (part 2)

Inspired by this video by Ben Eater. This challenge forms a pair with Decode USB packets. The USB 2.0 protocol uses, at a low level, a line code called non-return-to-zero encoding (specifically, a ...
user avatar
  • 18.5k
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 ...
user avatar
  • 18.5k
18 votes
8 answers
1k views

Sum of set bits from 1 to n

Given an integer \$ n \$ \$ (n \ge 1) \$, return/output the total number of set bits between \$ 1 \$ and \$ n \$ inclusive. To make the problem more interesting, your solution must run with a time ...
user avatar
20 votes
13 answers
888 views

Duplicates in "n × hamming weight of n" sequence

Background The sequence in the title is A245788 "n times the number of 1's in the binary expansion of n" ("times" here means multiplication), which starts like this: ...
user avatar
  • 62.1k
21 votes
21 answers
3k views

Fibonacci Encoding

Fibonacci coding is a universal code, which can encode positive integers of any size in an unambiguous stream of bits. To encode an integer \$ n \$: Find the largest Fibonacci number less than or ...
user avatar
  • 18.5k
26 votes
11 answers
2k views

Test if a Gray code is Beckett

Background An \$n\$-bit Gray code is an ordering of \$2^n\$ binary sequences so that adjacent sequences always differ by exactly one bit. A Beckett-Gray code is a special kind of Gray code. In ...
user avatar
  • 62.1k
7 votes
2 answers
183 views

Filetype Color Codes

On Unix-like systems, the ls command lists files. GNU's version of ls also colors them according to their properties and the ...
user avatar
10 votes
11 answers
892 views

Elias omega coding: decoding

Related: Elias omega coding: encoding Background Elias omega coding is a universal code which can encode positive integers of any size into a stream of bits. Given a stream of bits \$S\$, the decoding ...
user avatar
  • 62.1k
21 votes
29 answers
2k views

Elias omega coding: encoding

Background Elias omega coding is a universal code which can encode positive integers of any size into a stream of bits. Given a positive integer \$N\$, the encoding algorithm is as follows: Start ...
user avatar
  • 62.1k
16 votes
8 answers
752 views

Close(st) Binary Boxes

Challenge: Given a list of non-negative integers, determine by how much you should increase each item to create the closest binary box with the resulting integer-list. What is a binary box? A binary ...
user avatar
18 votes
5 answers
1k views

Find a sequence in the binary digits of π

Given a binary sequence of finite length, find the starting position where this sequence first appears in the binary digits of π (after the decimal). You can assume that an answer exists for any input ...
user avatar
  • 1,787
-1 votes
2 answers
159 views

increment a binary number without arithmetic manipulations [closed]

Input: binary string Output: binary string that represents the binary input + 1 Example: Given 10111 as an input, output 11000 ...
user avatar
22 votes
36 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 ...
user avatar
23 votes
40 answers
5k 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 ...
user avatar
  • 11.1k
20 votes
14 answers
1k views

sporeball numbers

Background We've studied at least five different types of numbers based on the IDs of different users on this site. Why not study another? My user ID is \$91030_{10}\$. Its binary representation is \$...
user avatar
  • 1,648
15 votes
15 answers
1k views

Dovetail two blocks of bits

Check if two blocks of bits dovetail perfectly. Specifications A block of bits is a fixed sequence of 8 bits just like this for example : 11110101. For simplicity we refer to ...
user avatar
  • 9,426
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 ...
user avatar
  • 9,336
17 votes
18 answers
2k views

JFor? More like XNor

As it turns out, Python allows for 1j for to be compressed to 1jfor. However, jfor sounds ...
user avatar
  • 15.9k
22 votes
17 answers
1k views

Bubbler numbers

Background My user ID is 78410, or \$1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0_2\$. One interesting property of this number is that, in binary, it doesn't have three consecutive identical digits, and yet it ...
user avatar
  • 62.1k
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: ...
user avatar
  • 166k
13 votes
6 answers
466 views

Number of solutions to a binary weight equation

We define \$a(n)\$ as the 1-indexed position of \$n\$ in the sequence of positive integers with the same binary weight, i.e. the same number of 1's in their binary representation. This is A263017. ...
user avatar
  • 166k
12 votes
8 answers
1k views

Bit delivery in Bin City

sandbox Story Similar to a newspaper route you have been tasked with delivering bits to the residents of Bin City. Just as certain people like certain newspapers, the citizens of Bin City prefer ...
user avatar
  • 18k
10 votes
4 answers
302 views

Counting valid Binary Sudoku boards

Sequel of Counting valid Binary Sudoku rows. Background Binary Sudoku, also known as Takuzu, Binario, and Tic-Tac-Logic, is a puzzle where the objective is to fill a rectangular grid with two ...
user avatar
  • 62.1k
27 votes
26 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): ...
user avatar
  • 166k
21 votes
27 answers
3k views

A bit of a digital XOR

Here are the first 100 numbers of a sequence: ...
user avatar
26 votes
14 answers
2k views

Counting valid Binary Sudoku rows

Background Binary Sudoku, also known as Takuzu, Binario, and Tic-Tac-Logic, is a puzzle where the objective is to fill a rectangular grid with two symbols (0s and 1s for this challenge) under the ...
user avatar
  • 62.1k
3 votes
5 answers
170 views

Find the binary period [duplicate]

We know that not all fractions have a terminating binary representation. However every fraction can be written as a leading portion followed by a repeating portion. For example \$1/3\$ starts with \$...
user avatar
  • 84.9k
4 votes
15 answers
666 views

Convert a decimal integer to binary only using arithmetic operators

There are 10 types of people in the world, those who understand binary and those who do not. Where are you? Let's see! Challenge Your task is to convert a decimal integer to binary, only using a ...
user avatar
  • 11.9k
29 votes
43 answers
6k 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 ...
user avatar
  • 1,599
19 votes
10 answers
1k views

Fill the Golfeek gutter

Golfeek is the working name of an esolang I'm occasionally working on. One distinctive feature of this language is that each statement is encoded as a sequence of bits rather than a sequence of bytes. ...
user avatar
  • 166k
-1 votes
2 answers
168 views

Generating all Character possibilities with two characters [duplicate]

Introduction So the Challenge is to give out all combinations with two Inputs. The length of the string is also optional and you should be able to edit this. I've selected this channel because I ...
user avatar
  • 437
-1 votes
6 answers
218 views

Add 2 positive integers by playing with bits [closed]

Given 2 positive integers in any format you'd like, return their sum using only logic gates and bit shifts (see example below). Don't worry about overflow. EDIT: Using pre-written addition is ...
user avatar
  • 537
72 votes
48 answers
7k 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 ...
user avatar
-1 votes
13 answers
542 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 ...
user avatar

1
2 3 4 5