Muhammet Emin Gündoğar
05/25/2022, 8:35 PMfun Int.floorEven() = this and 0x01.inv()
I was reading a project and i saw this code but i could not understand why this code flooring the number to even i know 01 inverse equals to -2 because of 2's complement equals to 1's complement - 1 and 2 complent is negative of that number but i could not understand why this code will always work?ephemient
05/25/2022, 8:38 PMthis shr 1 shl 1
is equivalent to this.floorDiv(2) * 2
which also clears the lowest bit.Muhammet Emin Gündoğar
05/25/2022, 9:03 PMLandry Norris
05/25/2022, 9:11 PMephemient
05/25/2022, 9:11 PM0x01.inv() == 0xFFFFFFFE.toInt()
Landry Norris
05/25/2022, 9:12 PMMuhammet Emin Gündoğar
05/25/2022, 9:13 PMLandry Norris
05/25/2022, 9:13 PMMuhammet Emin Gündoğar
05/25/2022, 9:14 PMLandry Norris
05/25/2022, 9:14 PMephemient
05/25/2022, 9:14 PM1.inv()
as wellMuhammet Emin Gündoğar
05/25/2022, 9:15 PMephemient
05/25/2022, 9:15 PMLandry Norris
05/25/2022, 9:15 PMMuhammet Emin Gündoğar
05/25/2022, 9:16 PMephemient
05/25/2022, 9:17 PM