Quantcast
Channel: Active questions tagged bitwise - Code Golf Stack Exchange
Browsing index pages (61 articles)
↧

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

Problem:Find the number of leading zeroes in a 64-bit signed integerRules:The input cannot be treated as string; it can be anything where math and bitwise operations drive the algorithmThe output...

View Article


"Bit-borrow" two numbers

Did you know that a small number can borrow bits from a larger number? Here's an example. Let's say our two numbers 5 and 14. First, write them out in binary:5 14000101 001110First we take the smallest...

View Article


Reverse Bit Order of 32-bit Integers

Write the shortest code to reverse the bit order of a 32-bit integer.Rules:Input is assumed to be a valid integer or string equivalent if your language doesn't support numerical values (e.g. Windows...

View Article

Toggle some bits and get a square

Given an integer \$N>3\$, you have to find the minimum number of bits that need to be inverted in \$N\$ to turn it into a square number. You are only allowed to invert bits below the most...

View Article

Compare four integers, return word based on maximum

This function should take four integer inputs (a,b,c,d) and return a binary word based on which values equal the maximum of the four.The return value will be between 1 and 0xF.For example:a = 6, b =...

View Article


Digital Hardness of Integers

To find the digital hardness of an integer, take its binary representation, and count the number of times both a leading and trailing 1 can be removed until it either start or ends with a 0. The total...

View Article

Golf bit weaving

Note: the first half of this challenge comes from Martin Ender's previous challenge, Visualize Bit Weaving.The esoteric programming language evil has an interesting operation on byte values which it...

View Article

Double, XOR and do it again

We define the function g as g(n) = n XOR (n * 2) for any integer n > 0.Given x > 0, find the smallest integer y > 0 such that gk(y) = x for some k > 0.Examplex = 549549 = 483 XOR (483 * 2)...

View Article


Sort numbers by binary 1's count

GoalWrite a function or program sort an array of integers in descending order by the number of 1's present in their binary representation. No secondary sort condition is necessary.Example sorted...

View Article


Bitflip and negate

Given an integer, make an expression that produces it from 0 using unary negation - and bitwise complement ~ (~n = -n-1), with the operators applied right to left....-3 = ~-~-~0-2 = ~-~0-1 = ~0 0 = 0 1...

View Article

Do two numbers contain unique powers of 2

Break two numbers up into their powers of 2, if they share any, return a falsey value. Otherwise, return a truthy value.If one input is 0, the answer will always be truthy.if one input is 255, the...

View Article

Find the XOR Primes

In this challenge posed by xnor, we were asked to implement XOR multiplication. In this challenge the goal is to find the first n XOR primes. XOR primes are very similar to regular primes as you can...

View Article

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\$...

View Article


Two primes bitwise-anded into an odd number

Given a positive odd number \$n\$, return two primes\$p\$ and \$q\$ such that \$p\$bitwise-and\$q\$ equals \$n\$.\$n\$\$p\$\$q\$\$p\$& \$q\$13513333911139Shortest code in each language wins.Proof...

View Article

Two primes bitanded into an odd

Given a positive odd number, return any two primes which bitands(binary representation) up to the given number.E.g. 1=3&5, 3=3&3, 9=11&13.Shortest code in each language wins.Proof that it...

View Article


XOR sort an array

Given a key, and an array of strings, shuffle the array so that it is sorted when each element is XOR'd with the key.XOR'ing two stringsTo XOR a string by a key, XOR each of the character values of the...

View Article

Produce an XOR table

IntroductionXOR is a digital logic gate that implements an exclusive or. Most of the times, this is shown as ^. The four possible outcomes in binary:0 ^ 0 = 00 ^ 1 = 11 ^ 0 = 11 ^ 1 = 0This can also be...

View Article


Write a program that turns every 17th bit of a text file to a 1

My coworker and I work on a legacy piece of software that we hate sometimes.Whenever you run it, debug asserts come flying everywhere, and it's never a guarantee that anything will work. The motivation...

View Article

I'm in your subnets, golfing your code

ChallengeGiven an IPv4 address in dotted-quad notation, and an IPv4 subnet in CIDR notation, determine if the address is in the subnet. Output a distinct and consistent value if it is in the subnet,...

View Article

Mask an IP address and give its broadcast

BackgroundInspired by this Unix.SE question (and of course my own answer).When an IP address is specified for an interface, it is often given in this dotted-decimal form:a.b.c.d e.f.g.hwhere a.b.c.d is...

View Article
Browsing index pages (61 articles)


Latest Images