We’re rewarding the question askers & reputations are being recalculated! Read more.

# Questions tagged [binary]

Binary is the base 2 number system. Use this tag for challenges involving base 2.

156 questions
Filter by
Sorted by
Tagged with
2k views

### Counting in binary nybbles

This challenge is to output to your terminal, window, canvas or screen the numbers zero to 10 inclusive. Each outputted number must be shown as a 4-bit wide nybble, so zero must show as ...
5k views

### Find the number of leading zeroes in a 64-bit integer

Problem: Find the number of leading zeroes in a 64-bit signed integer Rules: The input cannot be treated as string; it can be anything where math and bitwise operations drive the algorithm The ...
3k 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 <...
7k 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 <...
999 views

### Minimum operations to get from one number to another

Let's define a simple language that operates on a single 8-bit value. It defines three bitwise operations (code explanation assumes 8-bit value variable): ...
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 ...
3k 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 ...
6k 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... ...
3k 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 ...
3k 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. ...
2k views

### Give me the Gray Code list of bit width n

The Gray Code is a sequence of binary numbers of bitwidth n where successive numbers differ only in one bit (see example output). Reference Example input: ...
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 ...
2k 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 ...
128 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 ...
194 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 ...
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.....
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.,...
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 multiplication ...
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 ...
3k views

### Densely packed decimal (DPD) to decimal

For nandgame fans: Please try out DPD to decimal in logic gates too! Background Densely packed decimal (DPD) is a way to efficiently store decimal digits in binary. It stores three decimal digits (...
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 ...
2k 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 2n items, zero-...
13k 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 ...
9k 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 ...
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 “...
5k 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 ...
515 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 ...
5k 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 ...
897 views

### The Binary Fences

Input: An integer n in the range 2 <= n <= 10 A list of positive integers Output: Convert the integers to their binary ...
580 views

### Fizzbuzz in any base

Challenge Input: An integer $b$ between 2 and 62 (inclusive). Output: Count from $1$ to the equivalent of $5000_{10}$ in base $b$, using any reasonable representation for the digits. ...
1k views

### Decrypt xor-encryption

Your task is to take an encrypted string as input, and output the string decrypted, to reveal its hidden message. The strings, both the input and output, will contain characters from this list of 64 ...
2k views

### Manchester encode a data stream

Manchester coding is a telecom protocol used in radio communications that guarantees bit transitions at a regular interval so a receiver can recover the clock rate from the data itself. It doubles the ...
6k 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 ...
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 ...
13k 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 ...
2k views

### Find the BCD difference of a number

BCD difference Given an integer n, convert it to BCD (binary-coded decimal) by replacing each decimal digit with its 4-digit binary representation ...
2k views

### Calculate hamming weight with low hamming weight

Create a program that computes the hamming weight of a string. Winner is the program with the lowest hamming weight. Rules: Hamming weight for an ASCII character is defined as the total number of ...
2k 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 ...
4k 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 ...
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 ...
14k 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: ...
4k 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 ...
453 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 ...
3k 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 ...
7k 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 ...
102 views

### Golf a bit-reversal table [duplicate]

The Premise: You are writing a C driver for a screen for use on an embedded system. The screen uses a tortured version of SPI that requires data to be sent LSb (least-significant-bit) first, but MSB (...
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 numbers ...
2k views

### Diluted Integer Sums

A positive integer can be diluted by inserting a 0 between two bits in its binary expansion. This means that an n-bit number has ...