Question
Q: I've written the necessary program for this assignment, checked if LF or CLRF was on, and I get a broken output in the screenshot
Q: I've written the necessary program for this assignment, checked if LF or CLRF was on, and I get a broken output in the screenshot below, but, if I run this in an online IDE for C, it comes out perfect, is my file FirstLastLab1methods.c written incorrectly for compile command "gcc Lab1main.c FirstLastLab1methods.c -o Lab1.out"?
Lab1main.c
-------------------
#include
int main() { unsigned int x = 0; unsigned int y = 0; int i;
printf("Test 1: "); displayBits(x);
printf("Test 2: "); x = setKthBit(x,10); displayBits(x); y = setKthBit(y,20); displayBits(y);
printf("Test 3: "); printf("%7u power of 2? %d ",x,isPowerOfTwo(x)); printf("%7u power of 2? %d ",y,isPowerOfTwo(y));
printf("Test 4: "); x = setKthBit(x,5); y = setKthBit(y,5); displayBits(x); displayBits(y); printf("%7u power of 2? %d ",x,isPowerOfTwo(x)); printf("%7u power of 2? %d ",y,isPowerOfTwo(y));
printf("Test 5: "); x = setKthBit(x,1); y = setKthBit(y,4); x = setKthBit(x,3); y = setKthBit(y,1); displayBits(x); displayBits(y); printf("%7d bits convert %u to %u ",getNoBits(x,y),x,y);
printf("Test 6: XOR of all numbers 1..5 "); x = computeXor(5); displayBits(x);
printf("Test 7: XOR of all numbers 1..33 "); x = computeXor(33); displayBits(x);
printf("Test 8: "); x = 122; y = 60; displayBits(x); displayBits(y); printf("%7d bits convert %u to %u ",getNoBits(x,y),x,y);
printf("Test 9: "); printf("%7u power of 2? %d ",0,isPowerOfTwo(0));
printf("Test 10: "); x=0; for (i=1; i
-------------------
FirstLastLab1methods.c
-------------------
#include
void displayBits ( unsigned int n) { unsigned int c, displayMask = 1
// loop through bits for ( c = 1; c
putchar( ' ' ); } // end function displayBites int isPowerOfTwo (unsigned int x) { while (((x % 2) == 0) && x > 1) /* While x is even and > 1*/ x /= 2; return (x == 1); } // end function isPowerOfTwo unsigned int setKthBit (unsigned int n, unsigned int k) { // kth bit of n is being set by this operator return ((1
// finding the no. of set bits in the xor result while (x) { count += (x & 1); x >>= 1; } // end while
return count; } // end function getNoBits unsigned int computeXor (unsigned int n) { switch( n & 3 ) // n % 4 { case 0: return n; case 1: return 1; case 2: return n + 1; case 3: return 0; } // end switch } // end function computerXor -------------------
Lab1.out (expected output)
-------------------
Test 1: 0 = 00000000 00000000 00000000 00000000 Test 2: 512 = 00000000 00000000 00000010 00000000 524288 = 00000000 00001000 00000000 00000000 Test 3: 512 power of 2? 1 524288 power of 2? 1 Test 4: 528 = 00000000 00000000 00000010 00010000 524304 = 00000000 00001000 00000000 00010000 528 power of 2? 0 524304 power of 2? 0 Test 5: 533 = 00000000 00000000 00000010 00010101 524313 = 00000000 00001000 00000000 00011001 4 bits convert 533 to 524313 Test 6: XOR of all numbers 1..5 1 = 00000000 00000000 00000000 00000001 Test 7: XOR of all numbers 1..33 1 = 00000000 00000000 00000000 00000001 Test 8: 122 = 00000000 00000000 00000000 01111010 60 = 00000000 00000000 00000000 00111100 3 bits convert 122 to 60 Test 9: 0 power of 2? 0 Test 10: 65535 = 00000000 00000000 11111111 11111111
Implement the following bit manipulation methods using C language. void displayBits (unsigned int n); unsigned int setKthBit (unsigned int n, int k); int is PowerOfTwo (unsigned int n); int getNoBits (unsigned int a, unsigned int b); unsigned int computeXor (unsigned int n); Descriptions of these functions are as follows: dsplayBits: Displays an unsigned integer in bits. Print a space after every 8 bits. setKthBit: Sets the kth bit of n from the right to 1. is PowerOfTwo: returns 1 of n is a power of 2 and 0 otherwise. getNoBits: returns the number of bits required to convert a to b. computeXor: computes the XOR of all the numbers from 1 to n (including n). The following files are available for you to use with this assignment: Lablmain.c Labl.out Descriptions of these files are as follows: Lablmain.c: This is the main file that calls the methods and includes the test cases Labl.out: This is the output when methods are implemented and called from Lab1main.c Add your methods to FirstLastLab1methods.c and compile it with assign1main.c as follows to produce the executable. gcc Lab1main.c FirstLastLab1methods.c -o Lab1 Redirect the output of executable and use Linux command diff to compare the output file with the one provided with the Labl.out. Modify if needed and submit your First LastLablmethods.cto BB. hen04:-/courses/cs3843) Tabl> cat Lab2 ELFp434 ($!444444@ DHHH getdratd /lib/1d-linux.so. 2GNUK tcharprintf_libc_start_mainGLIBC_2.0ii. .=6)|_gmon_start_libc. so. 6_10_stdin_usedputs gues - XP90B19 []IVE s PER hevhs- ESES DEDESS EIZES GESAMTERESSEEDSSESSERELDS E DETSES S E Emsdets $215! jatut U m it UWV50 $t$1$ESDE Implement the following bit manipulation methods using C language. void displayBits (unsigned int n); unsigned int setKthBit (unsigned int n, int k); int is PowerOfTwo (unsigned int n); int getNoBits (unsigned int a, unsigned int b); unsigned int computeXor (unsigned int n); Descriptions of these functions are as follows: dsplayBits: Displays an unsigned integer in bits. Print a space after every 8 bits. setKthBit: Sets the kth bit of n from the right to 1. is PowerOfTwo: returns 1 of n is a power of 2 and 0 otherwise. getNoBits: returns the number of bits required to convert a to b. computeXor: computes the XOR of all the numbers from 1 to n (including n). The following files are available for you to use with this assignment: Lablmain.c Labl.out Descriptions of these files are as follows: Lablmain.c: This is the main file that calls the methods and includes the test cases Labl.out: This is the output when methods are implemented and called from Lab1main.c Add your methods to FirstLastLab1methods.c and compile it with assign1main.c as follows to produce the executable. gcc Lab1main.c FirstLastLab1methods.c -o Lab1 Redirect the output of executable and use Linux command diff to compare the output file with the one provided with the Labl.out. Modify if needed and submit your First LastLablmethods.cto BB. hen04:-/courses/cs3843) Tabl> cat Lab2 ELFp434 ($!444444@ DHHH getdratd /lib/1d-linux.so. 2GNUK tcharprintf_libc_start_mainGLIBC_2.0ii. .=6)|_gmon_start_libc. so. 6_10_stdin_usedputs gues - XP90B19 []IVE s PER hevhs- ESES DEDESS EIZES GESAMTERESSEEDSSESSERELDS E DETSES S E Emsdets $215! jatut U m it UWV50 $t$1$ESDEStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started