diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2022-11-13 11:50:28 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2022-11-13 11:50:28 +0400 |
| commit | 4862c2cf3eafdb6fa017a4e86a6fad8b4fc64171 (patch) | |
| tree | 6f0600b01d01b479ced7cba77e21a8970c2e0300 /lab2/src/utils.rs | |
| parent | 31ede18fb5752b4524868be845b88d26bda13754 (diff) | |
Добавлена вторая лаба
Diffstat (limited to 'lab2/src/utils.rs')
| -rw-r--r-- | lab2/src/utils.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lab2/src/utils.rs b/lab2/src/utils.rs new file mode 100644 index 0000000..801a108 --- /dev/null +++ b/lab2/src/utils.rs @@ -0,0 +1,20 @@ +pub fn powmod(x: u64, p: u64, m: u64) -> u64 { + let mut res = x; + for _ in 1..p { + res = (res * x) % m; + } + return res; +} + +pub fn to_bytes(x: u64) -> (u8, u8, u8, u8) { + return ( + ((x >> 0) & 0xFF) as u8, + ((x >> 8) & 0xFF) as u8, + ((x >> 16) & 0xFF) as u8, + ((x >> 24) & 0xFF) as u8, + ); +} + +pub fn from_bytes(x1: u8, x2: u8, x3: u8, x4: u8) -> u64 { + return (x1 as u64) << 0 | (x2 as u64) << 8 | (x3 as u64) << 16 | (x4 as u64) << 24; +} |