I'm trying to implement a growth function that initializes new byte array same as old, and share to 0 for new bits. For instance, if my old size is 12 and I set 4 to 1
then I will get this:
0000100000000000
0123456789012345
If I use my growth function and my new size is 24, I should expect this:
000010000000000000000000
012345678901234567890123
I'm trying to use a for loop. I also need to copy the old bytes to new bytes through the old byteArraySize_. So far my code looks like this:
If you want to use the same algorithm for both growth and shrinkage, you’ll need to change line 10 to work on the minimum of the two array sizes instead.
Is this a class assignment? You are required to use a loop?
Just use a loop:
1 2 3 4 5 6 7 8 9
size_t n = 0;
for (; n < byteArraySize_; ++n) // copy elements loop
{
newByteArray[n] = byteArray_[n];
}
for (; n < newByteArraySize; ++n) // zero remaining elements loop
{
newByteArray[n] = 0;
}