{"record":{"id":"74146477f7ffd5e7","repo":"TheAlgorithms/Python","slug":"input-value-must-be-an-int-type-741464","errorCode":null,"errorMessage":"Input value must be an 'int' type","messagePattern":"Input value must be an 'int' type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/reverse_bits.py","lineNumber":65,"sourceCode":"    >>> reverse_bit(2550136832)\n    25\n    >>> reverse_bit(-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: The value of input must be non-negative\n\n    >>> reverse_bit(1.1)\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value must be an 'int' type\n\n    >>> reverse_bit(\"0\")\n    Traceback (most recent call last):\n        ...\n    TypeError: Input value must be an 'int' type\n    \"\"\"\n    if not isinstance(number, int):\n        raise TypeError(\"Input value must be an 'int' type\")\n    if number < 0:\n        raise ValueError(\"The value of input must be non-negative\")\n\n    result = 0\n    # iterator over [0 to 31], since we are dealing with a 32 bit integer\n    for _ in range(32):\n        # left shift the bits by unity\n        result <<= 1\n        # get the end bit\n        end_bit = number & 1\n        # right shift the bits by unity\n        number >>= 1\n        # add that bit to our answer\n        result |= end_bit\n    return result\n\n\nif __name__ == \"__main__\":","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/reverse_bits.py#L47-L83","documentation":"Raised by reverse_bit() when the argument is not an int. The function reverses the 32 bits of an integer with shifts (<<=, >>=, & 1), which only make sense for ints, so floats, strings, and bools-as-intent are rejected upfront. Note bool technically passes since isinstance(True, int) is True.","triggerScenarios":"Calling reverse_bit(1.1) or reverse_bit(\"0\") as shown in the doctests; also reverse_bit(None) or reverse_bit([1]).","commonSituations":"Parsing numeric options from argv or JSON that arrive as strings, or mixing APIs that return floats with this int-only bit utility.","solutions":["Convert first: reverse_bit(int(value)) when the value is a numeric string or whole float.","Add isinstance validation in calling code before invoking reverse_bit.","Keep the input in the documented domain: a non-negative 32-bit int."],"exampleFix":"# before\nreverse_bit(\"0\")  # TypeError: Input value must be an 'int' type\n\n# after\nreverse_bit(int(\"0\"))  # 0","handlingStrategy":"type-guard","validationCode":"if not isinstance(number, int):\n    raise TypeError(f'reverse_bit expects int, got {type(number).__name__}')","typeGuard":"def is_reversable_int(n: object) -> bool:\n    return isinstance(n, int) and not isinstance(n, bool) and n >= 0","tryCatchPattern":"try:\n    reverse_bit(n)\nexcept TypeError:\n    n = int(n)\n    result = reverse_bit(n)","preventionTips":["int() your inputs once at the edge (argv, JSON) rather than at every call site.","Lint call sites with mypy so non-int arguments are caught statically."],"tags":["bit-manipulation","type-error","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}