14 Ways to Reverse a 32-Bit Integer. (And Why They Don’t Matter Anymore)

It was 2017. Pre-AI, pre-COVID. A time when people worked in places called offices, and finding a place in one meant writing cover letters, sending CVs, and having an interview with a real person.

And there I was, sitting in a small room with a department manager and two senior engineers—the three people who would decide whether I was a fit for their team.

They were well prepared. Intro. Work description. Ten technical questions—all written on a single sheet of paper. Real professionals.

Among the questions was the greatest one I have ever received:

Reverse the bit order in a 32-bit integer.

I got a pen, and my job was to write a solution. While coding on paper, I was loudly explaining what I was doing and why. I went with a simple while loop and pointers—the simpler it is, the bigger the chance the thing will compile — or would have, if writing Ctrl+F9 with my pen had any effect.

Luckily, I did not get the job. Sometimes rejection is the best thing that can happen in your life.

But the question stayed in my head. Later, I found multiple solutions—including a single ARM instruction that does exactly that. It became a fun little obsession: benchmarking different implementations and comparing them.

Now fast forward and it’s 2026. Post-COVID. Mid-AI. I am sitting on the other side, interviewing a potential candidate.

Should we ask them to do an online assessment?

The task I received ten years ago can now be solved in 30 seconds. Including all solutions I was so proud to find myself, even more. Including solid reasoning for each version. So how do you see whether the person on the other side really understands what is going on?

And if they do understand—does it even make them a good candidate? Do they need to know how to reason about code at all?

Times have changed a lot, and building teams is no longer just about whether someone is “a good fit” today. It is about predicting whether a person will still be a good fit in an environment that is going to change dramatically over the next five years. And in that context, reversing bits may not be the most valuable skill at all.

Maybe the best question nowadays is much simpler:

“Tell me about a technical question that stayed with you long after the interview was over.”

Use Docker to compile C++ 20

Last time we created a simple Docker image that allowed building any OpenCV based application. Today we will go one step further and allow our image to compile spaceships.

By spaceship I mean the three-way comparison operator (<=>) – a new feature inside the C++ language (still not official released version 20). To use it we need a gcc 10 so lets add it to our image. We need to add same steps to our recipe that you would normally execute on your dev machine: get dependencies, clone, build and install. I also included the latest cmake version because the default one used by Ubuntu 18 (3.16.0) was not supporting the C++ 20 yet.

FROM ubuntu:18.04

ARG DEBIAN_FRONTEND=noninteractive

# GCC dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libgmp-dev \ 
    libmpfr-dev \
    libmpc-dev \ 
    bash \
    git \
    flex \
    gcc-multilib \
    && rm -rf /var/lib/apt/lists/*

# CMAKE dependencies
RUN apt-get update && apt-get install -y \
    libssl-dev \
    && rm -rf /var/lib/apt/lists/*

# OpenCV Library
RUN apt-get update && apt-get install -y --no-install-recommends\
    libopencv-dev \
    && rm -rf /var/lib/apt/lists/*

# Install CMAKE
RUN git clone https://github.com/Kitware/CMake.git cmake_repo && \
    cd cmake_repo && \
    git checkout v3.17.3 && \
    ./bootstrap && \
    make && \
    make install && \
    cd .. && \
    rm cmake_repo -r

# Install GCC
RUN git clone git://gcc.gnu.org/git/gcc.git gcc_repo && \
    cd gcc_repo && \
    git checkout releases/gcc-10.1.0 && \
    ./configure --enable-languages=c,c++ --disable-multilib && \
    make && \
    make install && \
    cd .. && \
    rm gcc_repo -r

# Set environment variables
ENV CC=/usr/local/bin/gcc
ENV export CXX=/usr/local/bin/g++

CMD cd /home/out && cmake /home/source/. && make    

After building the image we can run it and compile a special version of our demo application that makes use of the magic operator (branch gcc20).

Nice but we can do better than that. When creating an image we added some dependencies needed to build required libraries. We need them only during the build process and Docker provides nice mechanism to deal with such situations: multi-stage builds.

Using this Docker inside a Docker philosophy we can protect our final image from all unwanted dependencies. All we need to do is split our file into two parts – one that will produce needed artifacts and second that makes use of them.

FROM ubuntu:18.04 AS builder

ARG DEBIAN_FRONTEND=noninteractive

# Build image dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    libgmp-dev \ 
    libmpfr-dev \
    libmpc-dev \ 
    bash \
    git \
    flex \
    gcc-multilib \
    libssl-dev \
    checkinstall \
    && rm -rf /var/lib/apt/lists/*

# Build CMAKE
RUN git clone https://github.com/Kitware/CMake.git cmake_repo && \
    cd cmake_repo && \
    git checkout v3.17.3 && \
    mkdir out && \
    ./bootstrap && \
    make && \
    checkinstall -D --pkgname=cmake --pkgversion=3.17.3


# Build GCC
RUN git clone git://gcc.gnu.org/git/gcc.git gcc_repo && \
    cd gcc_repo && \
    git checkout releases/gcc-10.1.0 && \
    mkdir out && \
    ./configure --enable-languages=c,c++ --disable-multilib && \
    make && \
    checkinstall -D --pkgname=gcc --pkgversion=10.1.0


# Target image
FROM ubuntu:18.04

ARG DEBIAN_FRONTEND=noninteractive

# OpenCV Library
RUN apt-get update && apt-get install -y --no-install-recommends\
    libopencv-dev \
    libmpc-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy packages from builder image
COPY --from=builder /cmake_repo/*.deb .
COPY --from=builder /gcc_repo/*.deb .

# Install CMAKE and GCC
RUN apt install ./*.deb && rm *.deb

# Set environment variables
ENV CC=/usr/local/bin/gcc
ENV export CXX=/usr/local/bin/g++

CMD cd /home/out && cmake /home/source/. && make

Here we created 2 packages containing compiled versions of cmake and gcc. We copy and install them when creating production image.