Last Updated: February 25, 2016
·
1.741K
· thiago

Bitwise trick for parsing float to int in JavaScript

Bitwise trick for parsing float point to int: use double negation ~~3.33 => 3

2 Responses
Add your response

What language does this work in specifically? I'm not aware of any that it's even valid syntax, let along a "bitwise" way to coerce floats.

Bitwise is implicitly not going to work unless you happen to know how your floats are encoded.

over 1 year ago ·

@richoh My bad, it works just with javascript. I thought I've tested it with other languages but I didn't.

over 1 year ago ·