From f3946e67fa913eb7f2db29687fe240f5c566fd48 Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Tue, 28 Jul 2026 23:50:02 +0300 Subject: [PATCH 1/2] New bitwise operations and optimizations --- .../gmod_wire_expression2/core/bitwise.lua | 58 +++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/bitwise.lua b/lua/entities/gmod_wire_expression2/core/bitwise.lua index 32354093c1..39881e9e03 100644 --- a/lua/entities/gmod_wire_expression2/core/bitwise.lua +++ b/lua/entities/gmod_wire_expression2/core/bitwise.lua @@ -1,47 +1,83 @@ --- By asiekierka, 2009 -- ---Non-luabit XOR by TomyLobo-- - __e2setcost(2) +local bit = bit + e2function number bAnd(a, b) return bit.band(a, b) end + e2function number bOr(a, b) return bit.bor(a, b) end + e2function number bXor(a, b) return bit.bxor(a, b) end + +e2function number bShar(a, b) + return bit.arshift(a, b) +end + e2function number bShr(a, b) return bit.rshift(a, b) end + e2function number bShl(a, b) return bit.lshift(a, b) end + +e2function number bRol(a, b) + return bit.rol(a, b) +end + +e2function number bRor(a, b) + return bit.rol(a, b) +end + +e2function number bSwap(n) + return bit.bswap(n) +end + +e2function number bToBit(n) + return bit.tobit(n) +end + e2function number bNot(n) return bit.bnot(n) end -e2function number bNot(n,bits) + +e2function number bNot(n, bits) if bits >= 32 or bits < 1 then - return (-1)-n + return -1 - n else - return (math.pow(2,bits)-1)-n + return 2 ^ bits - 1 - n end end +e2function string bToHex(n) + return bit.tohex(n) +end + +e2function string bToHex(n, chars) + return bit.tohex(n, chars) +end -e2function number operator_band( a, b ) +e2function number operator_band(a, b) return bit.band(a, b) end -e2function number operator_bor( a, b ) + +e2function number operator_bor(a, b) return bit.bor(a, b) end -e2function number operator_bxor( a, b ) + +e2function number operator_bxor(a, b) return bit.bxor(a, b) end -e2function number operator_bshr( a, b ) + +e2function number operator_bshr(a, b) return bit.rshift(a, b) end -e2function number operator_bshl( a, b ) + +e2function number operator_bshl(a, b) return bit.lshift(a, b) end From 1d94d7868bb0c2868d308927cb7004b06faef3ec Mon Sep 17 00:00:00 2001 From: Astralcircle <142503363+Astralcircle@users.noreply.github.com> Date: Tue, 28 Jul 2026 23:51:19 +0300 Subject: [PATCH 2/2] Fix --- lua/entities/gmod_wire_expression2/core/bitwise.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/bitwise.lua b/lua/entities/gmod_wire_expression2/core/bitwise.lua index 39881e9e03..0c569c8558 100644 --- a/lua/entities/gmod_wire_expression2/core/bitwise.lua +++ b/lua/entities/gmod_wire_expression2/core/bitwise.lua @@ -31,7 +31,7 @@ e2function number bRol(a, b) end e2function number bRor(a, b) - return bit.rol(a, b) + return bit.ror(a, b) end e2function number bSwap(n)