Bitwise operators in Reason


#1

Hi good folks! Do you have a recommended resource for learning how to do bitwise operators on bytes in ReasonML? I was looking through docs, APIs and searches but couldn’t find any pointers.

I’m still learning the ropes on ReasonML, how everything is organized and documented and how to search for answers, so apologies in advance if I missed something obvious

I appreciate your pointers :slight_smile:


#2

OCaml has bitwise operations in its stdlib (see https://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html).

They are infix operators and their names are land, lor, lxor, lnot, lsl, lsr and asr.


#3

Thanks @anmonteiro!

If my goal is to be able to do these operations over Reason’s type Bytes and ensure that the operations are both valid for JS/Node land and OCaml, I wouldn’t be able to use OCaml stdlib, right? If it is possible, do you have any url to a snippet in which I could learn how to do it?


#4

I assume you wanna do one byte at a time. For that you can extract the char code at each position from your value and perform bitwise operations on it.