diff --git a/lua/entities/gmod_wire_expression2/core/bitwise.lua b/lua/entities/gmod_wire_expression2/core/bitwise.lua index 32354093c1..0c569c8558 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.ror(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 diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index c0794cf209..ddb4cab7b0 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1548,6 +1548,13 @@ E2Helper.Descriptions["bShl(nn)"] = "Performs bitwise shift left on the first nu E2Helper.Descriptions["bShr(nn)"] = "Performs bitwise shift right on the first number by the amount of the second" E2Helper.Descriptions["bNot(n)"] = "Performs a binary Not" E2Helper.Descriptions["bNot(nn)"] = "Performs a binary Not. The second argument is the length of the number you wish to perform Not on in bits" +E2Helper.Descriptions["bShar(nn)"] = "Performs arithmetic shift right on the first number by the amount of the second (preserves sign)" +E2Helper.Descriptions["bRol(nn)"] = "Performs a bitwise rotate left on the first number by the amount of the second" +E2Helper.Descriptions["bRor(nn)"] = "Performs a bitwise rotate right on the first number by the amount of the second" +E2Helper.Descriptions["bSwap(n)"] = "Swaps the byte order of the number (endian swap)" +E2Helper.Descriptions["bToBit(n)"] = "Normalizes and converts the number to a 32-bit signed integer" +E2Helper.Descriptions["bToHex(n)"] = "Converts the number to a hexadecimal string (8 digits)" +E2Helper.Descriptions["bToHex(nn)"] = "Converts the number to a hexadecimal string with the specified number of digits" -- EGP E2Helper.Descriptions["egpAlign(xwl:nn)"] = "Changes the horizontal alignment. Works on: text and text layout. Number can be 0, 1 or 2"