 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sat Feb 26, 2022 10:49 am Post subject: Understanding how binary works |
|
|
I wanted to make function that will recognize the bit value Code: | local val = (1<<3) --Entity have no collision
val = 188 --Can't explain what in there |
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1516
|
Posted: Sat Feb 26, 2022 1:57 pm Post subject: |
|
|
Code: | OR, XOR, AND = 1, 3, 4
function bitoper(a, b, oper)
local r, m, s = 0, 2^31
repeat
s,a,b = a+b+m, a%m, b%m
r,m = r + m*oper%(s-a-b), m/2
until m < 1
return math.floor(r)
end
print(bitoper(194,188,OR)) --> 254
print(bitoper(167,188,XOR)) --> 27
print(bitoper(188,178,AND)) --> 176 |
or
Code: | first = {1, 2, 3, 4, 5, 6}
second = {4, 5, 6, 7, 8, 9}
result=""
for i,k in pairs(first) do
--aa=k | second[i] --> 5,7,7,7,13,15
--aa=k & second[i] --> 0,0,2,4,0,0
--aa=k - second[i] --> -3,-3,-3,-3,-3,-3
--aa=second[i] - k --> 3,3,3,3,3,3
aa=k ^ second[i] --> 1.0,32.0,729.0,16384.0,390625.0,10077696.0
result=result .. aa .. ","
end
print(result) |
Quote: | 3.4.2 – Bitwise Operators
Lua supports the following bitwise operators:
&: bitwise AND
|: bitwise OR
~: bitwise exclusive OR
>>: right shift
<<: left shift
~: unary bitwise NOT
All bitwise operations convert its operands to integers, operate on all bits of those integers, and result in an integer.
Both right and left shifts fill the vacant bits with zeros. Negative displacements shift to the other direction; displacements with absolute values equal to or higher than the number of bits in an integer result in zero (as all bits are shifted out). |
Code: | print(3 & 5) --bitwise and ..1
print(3 | 5) --bitwise or ..7
print(3 ~ 5) --bitwise xor ..6
print(7 >> 1) --bitwise right shift ..3
print(7 << 1) --bitwise left shift ..14
print(~7) -- bitwise not ..-8 |
_________________
|
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Feb 27, 2022 1:56 am Post subject: |
|
|
Code: | local proofs
local BulletProof = (1<<3)
local FallProof = (1<<4)
local DamageProof = (1<<5)
proofs = BulletProof + FallProof + DamageProof
return proofs --Having 56
--[[
I wanted to have a bits what in there
like:
1 : false
2 : false
3 : true
4 : true
5 : true
6 : false
7 : false
same as in cheat engine binary value type
--]] |
|
|
Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1516
|
Posted: Sun Feb 27, 2022 5:15 am Post subject: |
|
|
Code: | first = {1, 2, 3, 4, 5, 6, 7, 8, 9}
function conter(tbl,rst,frm)
result=0
for i,k in pairs(tbl) do
if k~=false then
if frm==1 then
aa=tonumber(rst) << i
result=tonumber(result) + aa
else
aa=tonumber(rst) >> i --aa=k >> tonumber(rst) = 5
result=tonumber(result) + aa
end
end
end
return result
end
first = {false, false, true, true, true, false, false, false, false}
print(conter(first,1,1)) -->> 56
print(conter(first,1,2)) -->> 0 |
or convert bits:
Code: | num=1 bits=1
print(bits<<num)
num=2 bits=1
print(bits<<num)
num=3 bits=1
print(bits<<num)
num=4 bits=1
print(bits<<num)
num=5 bits=1
print(bits<<num)
num=6 bits=1
print(bits<<num)
num=7 bits=1
print(bits<<num)
num=8 bits=1
print(bits<<num)
num=9 bits=1
print(bits<<num)
num=10 bits=1
print(bits<<num)
num=11 bits=1
print(bits<<num)
num=12 bits=1
print(bits<<num)
num=13 bits=1
print(bits<<num) |
result:
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
or value bits:
Code: | function toBits(num, bits)
local t={}
for b=bits,1,-1 do
rest=math.floor(math.fmod(num,2)) --or rest=math.fmod(num,2)
t[b]=rest
num=(num-rest)/2
end
--print(bits)
if num==0 then return t
else return {"false"} end
end
function findBits(num)
bits=0
bitschk=false
for i=0, 100 do
bits1=toBits(tonumber(num), i)
bits2=table.concat(bits1)
if bits2~="false" then
if bitschk==false then
bits=i
--print(bits2)
bitschk=true
end
end
end
return bits
end
numBits=findBits(25)
print(numBits) -->> 5
numBits=findBits(255)
print(numBits) -->> 8
numBits=findBits(2555)
print(numBits) -->> 12 |
_________________
|
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Feb 27, 2022 2:28 pm Post subject: |
|
|
ty
|
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|