I have the problem with the code, when I input 0xef1e4 0x5 3, it doesn't execute anything.
I get the code from https://www.chegg.com/homework-help/programming-in-c-4th-edition-chapter-11-problem-6e-solution-9780321776419
but it seems error
#include <stdio.h>
int intSize(void)
{
unsigned int n= ~0;
int counter = 4;
while(n>0)
{
n=n>>1;
counter++;
}
return counter-1;//account for sign bit
}
//function to calculate the min number of bits needed to represent
a value
int numberOfBits(unsigned int x)
{
int sizeOfInt=intSize();
int counter = 0;
unsigned int temp = 1<<(sizeOfInt - 1);
while((temp | x) != x)
{
temp = temp >>1;
counter++;
}
return sizeOfInt - counter;
}
//function to return the n right most bits
int rightMost(int pattern, int n)
{
int temp, rightMost;
temp = ~0;
temp = temp<<n;
temp = ~temp;
rightMost = pattern &temp;
return rightMost;
}
int bitpat_search(int source, int pattern, int n)
{
int pRightMost, sourceBits, inder, res, index;
pRightMost = rightMost(pattern, n);
sourceBits = numberOfBits(source);
index=(sourceBits - n);
res=-1;
while(index>=0)
{
if((rightMost(source,n)^pRightMost)==0)
res = index;
source =source>>1;
index=index-1;
}
return res;
}
int main(void)
{
int index, source, pattern, n;
printf("\nEnter 3 arguments(source pattern n):");
scanf("%i %i %i, &source,&pattern, &n");
printf("The %i most bits of %i is %i\n", n, pattern,
rightMost(pattern, n));
index = bitpat_search(source, pattern, n);
printf("Pattern is at index %i\n", index);
return 0;
}
Here is the code provided above with slight modification while taking input now it executes. just modified the scanf statements look for bold text in the code for changed lines
C CODE
#include <stdio.h>
int intSize(void)
{
unsigned int n= ~0;
int counter = 4;
while(n>0)
{
n=n>>1;
counter++;
}
return counter-1;//account for sign bit
}
//function to calculate the min number of bits needed to represent
a value
int numberOfBits(unsigned int x)
{
int sizeOfInt=intSize();
int counter = 0;
unsigned int temp = 1<<(sizeOfInt - 1);
while((temp | x) != x)
{
temp = temp >>1;
counter++;
}
return sizeOfInt - counter;
}
//function to return the n right most bits
int rightMost(int pattern, int n)
{
int temp, rightMost;
temp = ~0;
temp = temp<<n;
temp = ~temp;
rightMost = pattern &temp;
return rightMost;
}
int bitpat_search(int source, int pattern, int n)
{
int pRightMost, sourceBits, inder, res, index;
pRightMost = rightMost(pattern, n);
sourceBits = numberOfBits(source);
index=(sourceBits - n);
res=-1;
while(index>=0)
{
if((rightMost(source,n)^pRightMost)==0)
res = index;
source =source>>1;
index=index-1;
}
return res;
}
int main(void)
{
int index, source, pattern, n;
printf("\nEnter source (hexadecimal):");
scanf("%i, &source");
printf("\nEnter pattern (hexadecimal):");
scanf("%i,&pattern");
printf("\nEnter n (hexadecimal):");
scanf("%i,&n");
printf("The %i most bits of %i is %i\n", n, pattern,
rightMost(pattern, n));
index = bitpat_search(source, pattern, n);
printf("Pattern is at index %i\n", index);
return 0;
}
OUTPUT OF SCREENSHOT

Enter source (hexadecimal):Oxefle4 Enter pattern (hexadecimal):0x5 Enter n (hexadecimal):0x3 The 1 most bits of is Pattern is at index 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - Process exited after 12.38 seconds with return value o Press any key to continue...
I have the problem with the code, when I input 0xef1e4 0x5 3, it doesn't execute...
I need help of how to include the merge sort code into this counter code found below: #include<iostream> using namespace std; int bubble_counter=0,selection_counter=0; // variables global void bubble_sort(int [], int); void show_array(int [],int); void selectionsort(int [], int ); int main() { int a[7]={4,1,7,2,9,0,3}; show_array(a,7); //bubble_sort(a,7); selectionsort(a,7); show_array(a,7); cout<<"Bubble counter = "<<bubble_counter<<endl; cout<<"Selection Counter = "<<selection_counter<<endl; return 0; } void show_array(int array[],int size) { for( int i=0 ; i<size; i++) { cout<<array[i]<< " "; } cout<<endl; } void bubble_sort( int array[],...
How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...
C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...
C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...
What to do Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of...
Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...
Here is the code I made, but the test case is not working, it
goes wrong when the binary string convert to decimal. please
help.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <math.h>
#include <locale>
using namespace std;
// function for option 1
void decToBin(int number)
{
int array[16];
int i = 0;
for (int counter = 0;
counter < 16; counter++)
{
array[counter] = 0;
}
while (number > 0)
{...
The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...
PUT INTO PYTHON CODE #include <stdio.h> #include <float.h> int main(void) { float a = 1; float b = 0.5; float c = a + b; int bits = 0; while (c != a) { bits = bits + 1; b = b / 2; c = a + b; } printf("%d\n",bits); return 0; }
the code needs to be modifed. require a output for the
code
Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...