{"record":{"id":"6f2b07b4e137d26d","repo":"TheAlgorithms/Python","slug":"operation-can-not-be-conducted-on-an-object-of-typ","errorCode":null,"errorMessage":"operation can not be conducted on an object of type {type(number).__name__}","messagePattern":"operation can not be conducted on an object of type (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"bit_manipulation/reverse_bits.py","lineNumber":23,"sourceCode":"    >>> get_reverse_bit_string(9)\n    '10010000000000000000000000000000'\n    >>> get_reverse_bit_string(43)\n    '11010100000000000000000000000000'\n    >>> get_reverse_bit_string(2873)\n    '10011100110100000000000000000000'\n    >>> get_reverse_bit_string(2550136832)\n    '00000000000000000000000000011001'\n    >>> get_reverse_bit_string(\"this is not a number\")\n    Traceback (most recent call last):\n        ...\n    TypeError: operation can not be conducted on an object of type str\n    \"\"\"\n    if not isinstance(number, int):\n        msg = (\n            \"operation can not be conducted on an object of type \"\n            f\"{type(number).__name__}\"\n        )\n        raise TypeError(msg)\n    bit_string = \"\"\n    for _ in range(32):\n        bit_string += str(number % 2)\n        number >>= 1\n    return bit_string\n\n\ndef reverse_bit(number: int) -> int:\n    \"\"\"\n    Take in a 32 bit integer, reverse its bits, return a 32 bit integer result\n\n    >>> reverse_bit(25)\n    2550136832\n    >>> reverse_bit(37)\n    2751463424\n    >>> reverse_bit(21)\n    2818572288\n    >>> reverse_bit(58)","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/bit_manipulation/reverse_bits.py#L5-L41","documentation":"Raised by get_reverse_bit_string() when its argument is not an int. The helper builds a 32-bit LSB-first bit string using % and >>=, operations the function deliberately refuses to run on non-integers. The message interpolates the actual type name (e.g. 'str', 'float') so callers can see what they passed.","triggerScenarios":"Calling get_reverse_bit_string('this is not a number'), get_reverse_bit_string(25.0), or passing any non-int object such as a list or None.","commonSituations":"Reading bits from JSON/text config where values arrive as strings, forwarding unvalidated CLI input, or passing a float that 'looks' integral (25.0).","solutions":["Convert to int before calling: get_reverse_bit_string(int(value)).","Validate at the boundary: if not isinstance(number, int): raise TypeError(...) in your own wrapper.","If floats are legitimate, decide policy: int(x) truncates, round(x) rounds — then call."],"exampleFix":"# before\nget_reverse_bit_string(\"25\")  # TypeError: operation can not be conducted on an object of type str\n\n# after\nget_reverse_bit_string(int(\"25\"))  # ok","handlingStrategy":"type-guard","validationCode":"if not isinstance(number, int):\n    number = int(number)  # or raise your own error","typeGuard":"def is_int(value: object) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":"try:\n    get_reverse_bit_string(x)\nexcept TypeError as e:\n    if 'operation can not be conducted' in str(e):\n        x = int(x)","preventionTips":["Keep numeric data as int end-to-end; avoid str/float round-trips.","Centralize parsing (int()) at the I/O boundary so internals always see ints."],"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"}