-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding toBytes and fromBytes to Nat32 #269
base: master
Are you sure you want to change the base?
Conversation
Thanks! We probably want to indicate the endianness in these functions, i.e. Also, the |
[ Prim.natToNat8(Prim.nat32ToNat((x >> 24) & (255))), | ||
Prim.natToNat8(Prim.nat32ToNat((x >> 16) & (255))), | ||
Prim.natToNat8(Prim.nat32ToNat((x >> 8) & (255))), | ||
Prim.natToNat8(Prim.nat32ToNat((x & 255))) ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
[ Prim.natToNat8(Prim.nat32ToNat((x >> 24) & (255))), | |
Prim.natToNat8(Prim.nat32ToNat((x >> 16) & (255))), | |
Prim.natToNat8(Prim.nat32ToNat((x >> 8) & (255))), | |
Prim.natToNat8(Prim.nat32ToNat((x & 255))) ]; | |
[ Prim.natToNat8(Prim.nat32ToNat(x >> 24 & 255)), | |
Prim.natToNat8(Prim.nat32ToNat(x >> 16 & 255)), | |
Prim.natToNat8(Prim.nat32ToNat(x >> 8 & 255)), | |
Prim.natToNat8(Prim.nat32ToNat(x & 255)) ]; |
(Prim.natToNat32(Prim.nat8ToNat(x[0])) << 24) + | ||
(Prim.natToNat32(Prim.nat8ToNat(x[1])) << 16) + | ||
(Prim.natToNat32(Prim.nat8ToNat(x[2])) << 8) + | ||
(Prim.natToNat32(Prim.nat8ToNat(x[3]))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Prim.natToNat32(Prim.nat8ToNat(x[0])) << 24) + | |
(Prim.natToNat32(Prim.nat8ToNat(x[1])) << 16) + | |
(Prim.natToNat32(Prim.nat8ToNat(x[2])) << 8) + | |
(Prim.natToNat32(Prim.nat8ToNat(x[3]))); | |
Prim.natToNat32(Prim.nat8ToNat(x[0])) << 24 + | |
Prim.natToNat32(Prim.nat8ToNat(x[1])) << 16 + | |
Prim.natToNat32(Prim.nat8ToNat(x[2])) << 8 + | |
Prim.natToNat32(Prim.nat8ToNat(x[3])); |
@@ -2,6 +2,7 @@ | |||
/// | |||
/// Most operations are available as built-in operators (e.g. `1 + 1`). | |||
import Nat "Nat"; | |||
import Nat8 "Nat8"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this module actually used?
still ok? |
d52aecd
to
08507fc
Compare
I'm not sure how to go about testing, but I tried to add tests as well. This same pattern can be followed for the hard edged NatXz. The Nat to bytes will need a bit more finesse than I have at the moment.