Write c code of encoder decoder for On–off keying
- User
Write c code of encoder decoder for On–off keying
- Assistant
On-Off Keying (OOK) is a simple modulation technique in which the presence of a signal is used to indicate a binary '1' and the absence of a signal is used to indicate a binary '0'. I'll provide a simple C code implementation of an encoder and decoder for OOK modulation:
#include <stdio.h> #include <stdbool.h> // Function to encode a binary message using OOK modulation void ook_encoder(bool* message, size_t msg_len, bool* encoded_signal, size_t* encoded_len) { for (size_t i = 0; i < msg_len; i++) { encoded_signal[i] = message[i]; } *encoded_len = msg_len; } // Function to decode an OOK modulated signal void ook_decoder(bool* encoded_signal, size_t encoded_len, bool* message, size_t* msg_len) { for (size_t i = 0; i < encoded_len; i++) { message[i] = encoded_signal[i]; } *msg_len = encoded_len; } int main() { bool message[] = { 1, 0, 1, 1, 0, 0, 1 }; size_t msg_len = sizeof(message) / sizeof(message[0]); bool encoded_signal[msg_len]; size_t encoded_len = 0; ook_encoder(message, msg_len, encoded_signal, &encoded_len); printf("Encoded Signal: "); for (size_t i = 0; i < encoded_len; i++) { printf("%d ", encoded_signal[i]); } printf("\n"); bool decoded_message[msg_len]; size_t decoded_len = 0; ook_decoder(encoded_signal, encoded_len, decoded_message, &decoded_len); printf("Decoded Message: "); for (size_t i = 0; i < decoded_len; i++) { printf("%d ", decoded_message[i]); } printf("\n"); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.