Oct 6, 2019
in which the hero of this website discovers one mustn’t judge a bitwise op by its cover.
get a load of this:
bit.c
#include <stdio.h>
int main(int argc, const char *argv[])
{
int a = 2147483648;
int b = 7;
printf("%d\n", a & b);
return a & b;
}
[jared blog] (master)
$ gcc -o bit bit.c
[jared blog] (master)
$ ./bit
0
straight forward enough. Nothing suprising here.
bit.py
def bit() -> int:
a = 2147483648
b = 7
print(f'{a & b}')
return 0
if __name__ == '__main__':
bit()
[jared blog] (master)
$ python bit.py
0
same here. just some everyday run-of-the-mill stuff.
src/main.rs
fn main() {
let a: i32 = 2147483647;
let b: i32 = 7;
println!("{}", a & b);
}
[jared blog] (master)
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/blog`
7
O__o wut?
I don’t actually get what’s going on here yet.