BBitWhorl
Workflows

Coding workflows · Fixed-width bit rotation

03
Built around your work

A concrete starting point

Rotate an unsigned word left within a width from 1 through 64 bits. Check zero and full-width rotations with counts reduced modulo the width, rejecting negative counts and values that do not fit.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Fixed-width bit rotation

A concrete starting point
def rotate_left(value, count, width):
    if any(type(x) is not int for x in (value, count, width)):
        raise ValueError("rotate.type")
    if not 1 <= width <= 64 or not 0 <= value < (1 << width) or count < 0:
        raise ValueError("rotate.range")
    count %= width
    mask = (1 << width) - 1
    return ((value << count) | (value >> (width - count))) & mask

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗