Question: Using visual studio c++ #include #include typedef unsigned char byte; byte set_bit(byte register_value, int pin) { // (a) Modify the register value by setting the

Using visual studio c++

Using visual studio c++ #include #include typedef unsigned char byte; byte set_bit(byte

#include #include

typedef unsigned char byte;

byte set_bit(byte register_value, int pin) { // (a) Modify the register value by setting the designated pin // to 1 without altering the other pins, and return the result. // Hint: left shift; binary OR. }

byte flip_bits(byte register_value) { // (b) Flip all bits in the register value so that each bit that // is originally 1 becomes 0, and each bit that is originally 0 // becomes 1. // Hint: binary NOT. }

byte clear_bit(byte register_value, int pin) { // (c) Modify the register value by clearing the designated pin // (that is, setting it to 0) without altering any other pins, and // return the result. // Hint: left shift; binary NOT; binary AND. }

byte toggle_bit(byte register_value, int pin) { // (d) Modify the supplied register value by flipping the designated // pin, leaving all other pins unchanged. // Hint: left shift; binary XOR. }

//----------------------------------------------------------- #define REPEATS (5) #define BYTE_COUNT (256) #define PIN_COUNT (8) #define SEED ((unsigned) 314159) //-----------------------------------------------------------

/* ** Convert a byte to an integer with digits that look like the binary ** representation of the byte. ** ** For example: ** binstr(0x0c) == 1100, and ** binstr(0xcc) == 11001100. */ int binstr(byte b) { int result = 0;

for ( int i = 7; i >= 0; i-- ) { result = result * 10 + ((b >> i) & 1); }

return result; } //----------------------------------------------------------- int main(void) { srand(SEED);

for ( int i = 0; i

if ( i > 0 ) printf(" ");

printf(" set_bit(%08d, %d) = %08d ", binstr(register_value), pin, binstr( set_bit(register_value, pin))); printf(" flip_bits(%08d ) = %08d " , binstr(register_value), binstr( flip_bits(register_value ))); printf(" clear_bit(%08d, %d) = %08d ", binstr(register_value), pin, binstr( clear_bit(register_value, pin))); printf("toggle_bit(%08d, %d) = %08d ", binstr(register_value), pin, binstr(toggle_bit(register_value, pin))); } return 0; }

register_value, int pin) { // (a) Modify the register value by setting

$ ./sample_test_driver set_bit(01100001, 7) = 11100001 flip_bits(01100001 ) = 10011110 clear_bit(01100001, 7) = 01100001 toggle_bit(01100001, 7) = 11100001

set_bit(00111101, 2) = 00111101 flip_bits(00111101 ) = 11000010 clear_bit(00111101, 2) = 00111001 toggle_bit(00111101, 2) = 00111001

set_bit(00100101, 3) = 00101101 flip_bits(00100101 ) = 11011010 clear_bit(00100101, 3) = 00100101 toggle_bit(00100101, 3) = 00101101

set_bit(10000101, 4) = 10010101 flip_bits(10000101 ) = 01111010 clear_bit(10000101, 4) = 10000101 toggle_bit(10000101, 4) = 10010101

set_bit(00010001, 1) = 00010011 flip_bits(00010001 ) = 11101110 clear_bit(00010001, 1) = 00010001 toggle_bit(00010001, 1) = 00010011

Complete the implementation of the set bit. flip bits clear bit and toggle bit unctions. The hash tags for this exercise are: #cab202. and #cab282Bit Fiddling fter completing this exercise you will be able to manipulate bits with precision. These operations are required when programming at the hardware level. To complete the program, follow the instructions detailed in the in-line comments in the skeleton code below Notes Use this test driver to implement and test your function prior to submission

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!