wc3hrw
Last Updated: February 25, 2016
·
1.411K
· thiago
Dfdcc7fdb4b631ae9c30acd5ac6c2cbe

Bitwise trick for parsing float to int in JavaScript

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

Say Thanks
Respond

2 Responses
Add your response

4227
Richhealeyavatar

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 ·
4313
Dfdcc7fdb4b631ae9c30acd5ac6c2cbe

@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 ·