Many languages have a function or operator to calculate the bitwise complement (ones become zeros and vice versa). Roc has bitwiseAnd, bitwiseOr and bitwiseXor, as well as all common bit shift functions. I think a function bitwiseComplement would be a logical addition to complete this set of functions.
I have been making an md5 hash implementation in pure roc for which it is needed. I could get the implementation to work by using Num.maxU32 in combination with Num.bitwiseXor, but this solution is not generic to all integer types.
Can we call it bitwiseNot? I think that is a much more common and recognizable name.
Also, i think a generic solution is to use Num.subWrap 0 1 for the number type. So should be easy to implement in pure generic roc.
Brendan Hansknecht said:
Can we call it
bitwiseNot? I think that is a much more common and recognizable name.
Yeah sounds better indeed
Brendan Hansknecht said:
Also, i think a generic solution is to use
Num.subWrap 0 1for the number type. So should be easy to implement in pure generic roc.
Oh cool, I did not think of that, smart!
Alright, I'll implement it
@Kilian Vounckx I've actually been working on implementing the md5 algorithm in Roc, but it's been slow because I keep getting sidetracked implementing functions like bitwise complement, I didn't think to just ask it to be added to the stdlib :sweat_smile:
I have a working implementation, haven't benchmarked it though, or tested it with really large values. I will put it on here later when I have my pc with me
But yeah I had the same experience. I also implemented a chunks function to divide a list into parts. And going from bytes to integers can only be done in one direction iirc
Nice, I'm looking forward to see your implementation, then I'll compare with mine and see if I can help with performance
Kilian Vounckx said:
But yeah I had the same experience. I also implemented a
chunksfunction to divide a list into parts. And going from bytes to integers can only be done in one direction iirc
as in, there's no way to go from integers to bytes?
Exactly, There is are the Num.bytesToU__ functions, but no u__ToBytes functions. Also no way to specify endianness, so for md5 I ended up reimplementing the existing ones anyway
yeah ok cool, can you start a new #ideas thread for that? I have both thoughts and questions :big_smile:
Richard Feldman said:
yeah ok cool, can you start a new #ideas thread for that? I have both thoughts and questions :big_smile:
Hannes said:
Nice, I'm looking forward to see your implementation, then I'll compare with mine and see if I can help with performance
Here is what I have. But maybe this should become its own thread :sweat_smile:
Last updated: Jun 16 2026 at 16:19 UTC