Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [binary]

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

15
votes
5answers
761 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 ...
15
votes
5answers
954 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): ...
19
votes
45answers
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 ...
42
votes
25answers
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 ...
1
vote
0answers
96 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 (...
32
votes
15answers
4k 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 ...
31
votes
32answers
4k 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, ...
3
votes
2answers
307 views

Wanna be an Alchemist

Wanna be an Alchemist I've been watching Full Metal Alchemist these past days and I've been wondering, It is really possible to trans-mutate matter? In the real world, I don't know if it is possible, ...
8
votes
3answers
332 views

Compress to Impress

Inspired by both the challenge "Unique is Cheap" by @Laikoni, where the score is based on the challenge itself, as well as the JavaScript (ES6) answer of @ETHproductions for the "Palindrome ...
26
votes
22answers
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 ...
17
votes
23answers
1k views

Binary Substrings

Inspired by the fourth problem from BMO2 2009. Given a positive integer n as input or a parameter, return the number of positive integers whose binary representations occur as blocks in the binary ...
31
votes
50answers
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 ...
17
votes
7answers
2k views

Hilbert's binary Hotel

In this challenge you will be asked to implement any function (or full program) that fulfills two properties. Those properties are: Your function must be an injective (reversible) function from the ...
12
votes
22answers
1k 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 ...
23
votes
25answers
1k views

Binary Sequences

Given a binary number A as input with d > 1 digits, output a binary number B with d digits according to the following rules for finding the nth digit of B: The first digit of B is zero if the first ...
17
votes
20answers
1k 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 ...
29
votes
75answers
6k 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 ...
24
votes
23answers
3k views

Take a byte out of it!

Your task is to, given an unsigned integer n, find the largest number which can be created by removing a single byte (8 consecutive bits) of data. Example Given ...
32
votes
7answers
1k 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 ...
23
votes
16answers
3k views

Take one to make one

Challenge Given a list of positive integers, find if there exists a permutation where taking up to one bit from each of the integers, a binary number consisting of all ...
18
votes
8answers
1k views

Output the Source, One Bit at a Time

Write a non-empty program or function that when called outputs a single value, 1 or 0, and when called multiple times, the output numbers produce the binary representation of your program's source ...
18
votes
14answers
877 views

Binary Prime-Chunks

We are searching for a sequence Take the natural numbers 1,2,3,4,5,6,7,8,9,10,11,12,13,14... Convert to base-2 ...
20
votes
13answers
1k views

The Binary Square Diagonal Sequence

The binary-square-diagonal-sequence is constructed as follows: Take the sequence of positive natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ... Convert each number to ...
19
votes
7answers
845 views

Number of distinct non-empty subsequences of binary expansion

A subsequence is any sequence that you can get from another by deleting any amount of characters. The distinct non-empty subsequences of 100 are ...
18
votes
7answers
946 views

Longest hypercube path

Challenge You are given two distinct bit strings of the same length. (For example, 000 and 111.) Your goal is to find a path ...
68
votes
11answers
12k 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 ...
32
votes
33answers
4k 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 ...
9
votes
14answers
1k views

The Binary Binary Expansion

Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of 0 or 1 for each term: ...
1
vote
28answers
2k views

Binary to Hexadecimal

Convert a binary number (of any size) into a hexadecimal number. Input A POSITIVE binary number with just the 0s and 1s. A ...
10
votes
3answers
852 views

Blind binary adder

Imagine you have two boxes B(x) and B(y), each containing an unknown bit - 0 or 1, and a machine ...
1
vote
1answer
256 views

Minimum swaps to create an alternating binary string of ones and zeros [closed]

Given a binary string, that is it contains only 0s and 1s (number of zeros equals the number of ones) We need to make this string a sequence of alternate characters by swapping some of the bits, our ...
18
votes
16answers
2k views

It's a Bit of a Stretch․․․

Input: We take two inputs: An input b with two distinct values: Left and Right.† And a ...
15
votes
8answers
1k views

Generate unseen numbers

Let us say a substring is any continuous section of an original string. For example cat is a substring of concatenate. We will ...
29
votes
25answers
2k 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 ...
-5
votes
4answers
153 views

Binary Magic Cards [closed]

There's a cool magic trick that works using the power of binary. The effect of the trick is as follows: An audience member chooses some natural number in the range of ...
30
votes
9answers
2k 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 ...
22
votes
23answers
3k views

Fractal Cathedral

Given a positive integer n >= 1, output the first n rows of the following structure: ...
18
votes
23answers
2k views

Easy binary triangle

Given as input a positive integer n>=1, output the first n rows of the following triangle: ...
21
votes
14answers
1k views

Weakened Binary Walls

Inspired by Create a binary wall Given a list of positive integers, we can write them out all above each other like so, for [2, 6, 9, 4] as an example: ...
33
votes
28answers
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 ...
50
votes
62answers
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 ...
22
votes
30answers
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 <...
9
votes
5answers
231 views

I text the correct combo of ones and zeros

I recently listed to the song I'm a Textpert about texting while driving and one particular line in the song inspired this challenge. I never stoop so low as to text photos / Instead I text the ...
5
votes
5answers
106 views

Reflective binary ordering

The reverse of an n-bit number is just its n binary digits in reverse order: 001010010 → 010010100 Given a number n, generate all n-bit integers ([0, 2n-1]) in an arbitrary order, with ...
15
votes
10answers
906 views

Decrypt xor-encryption

Your task is to take an encrypted string as input, and output the string decrypted, to reveal it's hidden message. The strings, both the input and output, will contain characters from this list of 64 ...
28
votes
25answers
4k 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 ...
41
votes
11answers
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 ...
6
votes
2answers
330 views

Generate Hamming codes

Given a stream of bits, output the shortest possible Hamming code that encodes it. The steps to generate the Hamming code are as follows, although your submission does not necessarily have to conform ...
9
votes
6answers
358 views

Eyeballing the bits

Eyeballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation. So I want to ...
15
votes
10answers
2k views

Split me in half

You will be given a number x, where 0 <= x <= 2^32 - 1. You should output a list of numbers in decimal, after recursive ...