Packet Buffer Alias

#include <iostream>
#include <cstdint>

using namespace std;

// 1. Create the alias for an array of 8 bytes:
using Packet = uint8_t[8];

int main() {
    // 2. Declare a variable of type Packet and a temporary int array
    Packet data;
    // 3. Read 8 integers into the temporary array
    // Packet temporary;
    int temporary[8];
    for(int i = 0; i < 8; i++){
        cin >> temporary[i];
    }
    // 4. Assign values to the Packet buffer using static_cast<uint8_t>
    for(int i = 0; i < 8; i++){
        data[i] = static_cast<uint8_t>(temporary[i]);
    }
    // 5. Print values as numbers with space separation (no trailing space)
    for(int i = 0; i < 8; i++){
        cout << (unsigned int)data[i] <<" ";
    }
    return 0;
}

Solving Approach

 

 

 

 

 

Upvote
Downvote
Loading...

Input

10 20 30 40 50 60 70 80

Expected Output

10 20 30 40 50 60 70 80