{"success":true,"version":"v1","request":{"tool":"get_calculator_schema","calculator_id":"bitwise-operations"},"result":{"entity_type":"calculator","id":"bitwise-operations","calculator_id":"bitwise-operations","canonical_url":"https://tttkmbb.com/developer/bitwise-operations","name":"Bitwise Operations Calculator","title":"Bitwise Calculator – AND, OR, XOR, NOT and Shifts on 8/16/32-bit Two's-Complement Integers","category":"developer","category_name":"Developer & IT","tool_name":"calculate_bitwise_operations","featured_mcp_tool":false,"description":"Applies AND, OR, XOR, NOT, left shift, logical right shift or arithmetic right shift to integers of a chosen width (8, 16 or 32 bits) and reports the result as signed two's complement, unsigned, binary and hexadecimal.","use_when":"You need the exact bit pattern of a masked, combined or shifted integer as a CPU register of a given width would hold it, including the signed and unsigned readings of the result.","do_not_use_when":"Values exceed 32 bits (use arbitrary-precision arithmetic), you only need a base change (use base-converter), or you want floating-point bit layouts (use ieee-754-float).","inputs":[{"name":"a","label":"First operand (a)","type":"integer","required":true,"min":-2147483648,"max":4294967295,"description":"Integer operand; negative values are interpreted in two's complement of the chosen width.","example":12},{"name":"b","label":"Second operand (b) or shift count","type":"integer","required":false,"default":0,"min":-2147483648,"max":4294967295,"description":"Second operand for and/or/xor; the number of bit positions for shifts; ignored for not.","example":10},{"name":"operation","label":"Operation","type":"enum","required":true,"values":[{"value":"and","label":"AND (a & b)","aliases":["&"]},{"value":"or","label":"OR (a | b)","aliases":["|"]},{"value":"xor","label":"XOR (a ^ b)","aliases":["^","eor"]},{"value":"not","label":"NOT (~a)","aliases":["~","complement"]},{"value":"shift_left","label":"Shift left (a << b)","aliases":["shl","<<","lsl"]},{"value":"shift_right_logical","label":"Logical shift right (a >>> b, zero fill)","aliases":["shr",">>>","lsr"]},{"value":"shift_right_arithmetic","label":"Arithmetic shift right (a >> b, sign fill)","aliases":["sar",">>","asr"]}],"description":"Bitwise operation to apply.","example":"and"},{"name":"bit_width","label":"Bit width","type":"enum","required":false,"default":"32","values":[{"value":"8","label":"8-bit (byte)"},{"value":"16","label":"16-bit"},{"value":"32","label":"32-bit"}],"description":"Register width; results are truncated to this many bits and read as two's complement for the signed value.","example":"32"}],"outputs":[{"name":"result_signed","label":"Result (signed)","type":"integer","decimals":0,"description":"Result read as a two's-complement signed integer of the chosen width."},{"name":"result_unsigned","label":"Result (unsigned)","type":"integer","decimals":0,"description":"Result read as an unsigned integer of the chosen width."},{"name":"result_binary","label":"Result (binary)","type":"string","decimals":4,"description":"Result zero-padded to the bit width."},{"name":"result_hex","label":"Result (hex)","type":"string","decimals":4,"description":"Result in hexadecimal, zero-padded to width/4 digits."},{"name":"a_binary","label":"a (binary)","type":"string","decimals":4,"description":"First operand in two's complement at the chosen width."},{"name":"b_binary","label":"b (binary)","type":"string","decimals":4,"description":"Second operand (or shift count) in two's complement at the chosen width."},{"name":"expression","label":"Expression","type":"string","decimals":4,"description":"The evaluated expression in C-style notation."}],"input_schema":{"type":"object","properties":{"a":{"description":"Integer operand; negative values are interpreted in two's complement of the chosen width.","type":"integer","minimum":-2147483648,"maximum":4294967295,"examples":[12]},"b":{"description":"Second operand for and/or/xor; the number of bit positions for shifts; ignored for not.","type":"integer","minimum":-2147483648,"maximum":4294967295,"default":0,"examples":[10]},"operation":{"description":"Bitwise operation to apply.","type":"string","enum":["and","or","xor","not","shift_left","shift_right_logical","shift_right_arithmetic"],"examples":["and"]},"bit_width":{"description":"Register width; results are truncated to this many bits and read as two's complement for the signed value.","type":"string","enum":["8","16","32"],"default":"32","examples":["32"]}},"additionalProperties":false,"required":["a","operation"]},"output_schema":{"type":"object","properties":{"result_signed":{"description":"Result read as a two's-complement signed integer of the chosen width.","type":"integer"},"result_unsigned":{"description":"Result read as an unsigned integer of the chosen width.","type":"integer"},"result_binary":{"description":"Result zero-padded to the bit width.","type":"string"},"result_hex":{"description":"Result in hexadecimal, zero-padded to width/4 digits.","type":"string"},"a_binary":{"description":"First operand in two's complement at the chosen width.","type":"string"},"b_binary":{"description":"Second operand (or shift count) in two's complement at the chosen width.","type":"string"},"expression":{"description":"The evaluated expression in C-style notation.","type":"string"}}},"formula":"ua = a mod 2^w; ub = b mod 2^w; and/or/xor/not applied bit by bit; shift_left = (ua·2^b) mod 2^w; shift_right_logical = floor(ua / 2^b); shift_right_arithmetic = floor(sa / 2^b) with sa the signed reading; result_signed = result_unsigned − 2^w when result_unsigned ≥ 2^(w−1)","method":"Operands must fit the width either as signed (−2^(w−1) … 2^(w−1)−1) or unsigned (0 … 2^w−1) integers; shift counts must be 0 … w−1 as in C. All arithmetic is done with JavaScript 32-bit integer operators and masked to the width.","sources":[{"name":"Bitwise operation (Wikipedia)","url":"https://en.wikipedia.org/wiki/Bitwise_operation","type":"reference","retrieved_at":"2026-09-24"},{"name":"Two's complement (Wikipedia)","url":"https://en.wikipedia.org/wiki/Two%27s_complement","type":"reference","retrieved_at":"2026-09-24"}],"freshness":{"type":"static","max_age_seconds":null,"note":"Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output."},"examples":[{"name":"12 AND 10 (32-bit)","inputs":{"a":12,"b":10,"operation":"and","bit_width":"32"},"expected":{"result_signed":8,"result_unsigned":8,"result_binary":"00000000000000000000000000001000","result_hex":"0x00000008","a_binary":"00000000000000000000000000001100"},"url":"https://tttkmbb.com/api/v1/calculate/bitwise-operations?a=12&b=10&operation=and&bit_width=32"},{"name":"NOT 5 (8-bit)","inputs":{"a":5,"operation":"not","bit_width":"8"},"expected":{"result_unsigned":250,"result_signed":-6,"result_binary":"11111010","result_hex":"0xFA"},"url":"https://tttkmbb.com/api/v1/calculate/bitwise-operations?a=5&operation=not&bit_width=8"}],"faq":[{"q":"Why are there two right shifts?","a":"A logical shift fills the vacated high bits with zeros (unsigned division by 2^b); an arithmetic shift copies the sign bit, so negative numbers stay negative (signed division rounding toward −∞)."},{"q":"How is a negative operand handled?","a":"It is converted to its two's-complement pattern at the chosen width, e.g. −1 becomes 11111111 in 8 bits (unsigned 255), before the operation is applied."},{"q":"What if the shift count is larger than the width?","a":"The calculator rejects it with OUT_OF_RANGE; in C such shifts are undefined behaviour, and JavaScript masks the count to 5 bits."}],"tags":["bitwise calculator","and or xor","bit shift","two's complement","binary operations","hex"],"related":[{"calculator_id":"base-converter","reason":"Convert the operands or the result between binary, decimal and hexadecimal."},{"calculator_id":"subnet-calculator","reason":"Subnet masking is a 32-bit AND/OR."},{"calculator_id":"ieee-754-float","reason":"Bit layout of floating-point numbers."}],"links":{"html":"https://tttkmbb.com/developer/bitwise-operations","markdown":"https://tttkmbb.com/developer/bitwise-operations.md","json":"https://tttkmbb.com/developer/bitwise-operations.json","api":"https://tttkmbb.com/api/v1/calculate/bitwise-operations","schema":"https://tttkmbb.com/api/v1/calculators/bitwise-operations","openapi":"https://tttkmbb.com/openapi.json","mcp":"https://tttkmbb.com/mcp"},"version":"v1","updated_at":"2026-09-24"},"timestamp":"2026-09-24T03:44:38Z","next_actions":[{"tool":"run_calculator","calculator_id":"bitwise-operations","reason":"Run Bitwise Operations Calculator with the inputs above."}],"links":{"markdown":"https://tttkmbb.com/developer/bitwise-operations.md"}}