Write a c function that rotates a 32 bit int one bit to the left using
#define MASK0 0x00000001
#define MASK31 0x80000000
solution:
#include<stdio.h>
#define INT_BITS 32
/*Function to left rotate n by 1 bits*/
int leftRotate(int n, unsigned int d)
{
/* In n<<d, last d bits are 0. To put first 3 bits of n at
last, do bitwise or of n<<d with n >>(INT_BITS - d) */
return (n << d)|(n >> (INT_BITS - d));
}
int main()
{
int n = 16;
int d = 1;
printf("Left Rotation of %d by %d is ", n, d);
printf("%d", leftRotate(n, d));
return 0;
}
Output:
Please give thumbsup, if you like it. Thanks.
Write a c function that rotates a 32 bit int one bit to the left using...
write a C program!! Q2 and Q3 Write the following functioned int search(int a[], int n, int key, int **loc); a is an array to be searched, n is the number of elements in the array, key is the search key, and loc is a pointer to the first location of the search key in array a (if found) or NULL otherwise. The function returns 1 if key is found in a, and returns 0 otherwise. Write a main() and...
Write a program in C that reads a string of bits( so either a one or zero) in from the user one char at a time using the function getChar, which returns a char. hint in order to convert a char to an int, subtract the character. Then store the bits into an array. start with this: #include "stdio.h" #define MAX_BITS 32 int main() { printf("Enter up to 32 bits (hit 'enter' to terminate early): "); char bit = getchar();...
Write a C function that takes a long int y as argument as well as two integers n and m, the function should swap byte i and j of a long int y (64-Bit Integer).and returns a long int. long int swapBytes(long int y, int i, int j) Rules: Not allowed to use division, multiplication, or modulus, relative comparison (<, >, <=, >=), loops, switches, function calls, macros, conditionals (if or ?:) ALLOWED to use all bit level and logic...
Defining a binary in c language, write the function int binToDec(const int bin[]) to convert an eight-bit unsigned binary number to a nonnegative decimal integer. Do not output the decimal integer in the function. Test your function with interactive input?
Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...
I need help doing the code using Verilog modelsim Design a 32-bit register using the D Flip-Flop from part (1) so that it has the following features: (a) The Register has these ports Outputs: Q[31:0] Inputs: D[31:0] CLK is the clock signal EN is a synchronous signal for enabling the register. When EN is asserted at the sensitive edge of the CLK, the input D is loaded into the register. RESET We will leave this input unconnected, but will define...
C++ clock.h /* Write a function get_hours that returns an int and accepts an int seconds_since_1970 parameter */ int get_hours(int seconds_since_1970); /* Write a function get_minutes that returns an int and accepts an int seconds_since_1970 parameter */ int get_minutes(int seconds_since_1970); /* Write a function get_seconds that returns an int and accepts an int seconds_since_1970 parameter */ int get_seconds(int seconds_since_1970); clock.cpp #include "clock.h" /* Write get_hours code to return hours given seconds since 1970 int */ /* Write get_minutes code to...
Using lenguague C E5.5 (página 239) Write a function setbits(int x.char p.char n) that returns x with the n bits that begin at position p inverted (ie 1 changed to O and vice versa). Consider the position 0 the least significant bit of the variable x (remember that x is an integer)
using C: Write code for a function with the following prototype: /* * Mask with least signficant n bits set to 1 * Examples: n = 6 --> 0x3F, n = 17 --> 0x1FFFF * Assume 1 <= n <= w */ int lower_one_mask(int n); Your function should follow the bit-level integer coding rules. Be careful of the case n =w.
please do in c++Q4. Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int) that when passed a non-negative integer, returns the number of occurrences of the digit 7 in the number. So, for example: count7s(717) → 2 count75(7) →1 count7s(123) → 0 Q5. Write a C++ function of the form string mirrorEnds(string)that when given a string, looks for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...