Project 4 – memory
In this project, you are to perform the following:
- Reserve a 1024-byte block of memory.
- Fill that block of memory with random characters.
- Create an array, which is also 1,024 bytes in size.
- Copy the contents of the memory block into the array.
- Create a string that is limited to 1,024 bytes and is set using the
capacity
function. - Copy the contents of the memory block into the string.
At this point, you may be wondering why we have three identical blocks of memory. The simple reason is that you will now create a piece of code that will rotate each member in turn 3 times using a simple left-bit rotation and then 3 times to the right.
Bitwise rotation
Bitwise rotation is performed in Rust using the <<
and >>
operators.
For example, if we have a variable called x
that is rotated 3 to the left, we will write x << 3
with 3 to the right being x >> 3
.
Say we have x = 01101001, x << 3
will be 01001000 and x >> 3
will be 00001101.
Rotation caveat
While we can...