Fast Bit Duplication

View as PDF

Submit solution

Points: 10
Time limit: 2.5s
Memory limit: 64M

Author:
Problem type
Allowed languages
C, C++, Clang, Clang++, Fortran

Given 32-bit unsigned integers, duplicate each bit in-place in the integer.

For example:

  • \(10001_2\) becomes \(1100000011_2\)
  • \(11110_2\) becomes \(1111111100_2\)

Implementation

One function:

unsigned long long duplicatebits(unsigned long long);

Note: The function parameter is an unsigned long long instead of an unsigned int to remove the step of upcasting.

Your function may be called up to \(10^8\) times.


Comments

There are no comments at the moment.