Question

In: Computer Science

How could this be implemented in C? binstring[] = 1011001000010110000100010100110010010101101100011101000110010000100010100110010010101101100011101101000010001010011001001010110110001110001010011001001111100001000100010001000100010001 ~ 160 characters lon

How could this be implemented in C?

binstring[] = 1011001000010110000100010100110010010101101100011101000110010000100010100110010010101101100011101101000010001010011001001010110110001110001010011001001111100001000100010001000100010001

~ 160 characters long divided into groups of 5 ~

This function takes a starting position and the array of ‘1’ and ‘0’ and returns the character

representation of the five bits at that location.

    char byte_at( int position, const char binstring[] ) {

        }

Solutions

Expert Solution

file name 1.c

#include<stdio.h>
#include<math.h>
char byte_at( int position, char *binstring ) {
        int i=0,j=4;
        int tmp=0;
        while(i<5)
        {
                tmp+=(binstring[position+j]-48)*pow(2,i); 
                //starting from 5th bit from the position calculate the decimal representation of 5 bit binary .
                //'0' is 48 in decimal and '1' is 49
                i++;
                j--;
        }
        
                return tmp;

        }
int main()
{
        int position=0;
        char binstring[] = "1011001000010110000100010100110010010101101100011101000110010000100010100110010010101101100011101101000010001010011001001010110110001110001010011001001111100001000100010001000100010001";
        do
        {
        scanf("%d",&position);
        }while( position > 160); //loop to check value enter is between the range i.e less than 160 
        printf("character at the position %d are:  %c " ,position ,byte_at( position, binstring ) );
}

compile the program

gcc -o 1 1.c -lm

Related Solutions

In C++, cstring is implemented as an array of characters. What is the difference between cstring...
In C++, cstring is implemented as an array of characters. What is the difference between cstring and a regular array of characters? In other words, how do you distinguish them?
In C. elegans, lon-2 and unc-2 are X-linked genes. A lon-2 male is mated to a...
In C. elegans, lon-2 and unc-2 are X-linked genes. A lon-2 male is mated to a homozygous unc-2 hermaphrodite. Individual wild-type hermaphrodite offspring were then crossed to wild-type males. Among 359 male offspring from these matings, 9 were wild-type for both traits. What is the approximate map distance between lon-2 and unc-2?
A particular cipher is implemented by combining the ASCII representation of plaintext characters with pseudorandom bytes...
A particular cipher is implemented by combining the ASCII representation of plaintext characters with pseudorandom bytes (eight-bit binary strings of 1s and 0s) using the XOR function. In the process of encrypting a message, a character in the plaintext, a capital X, is XORed with the pseudorandom byte 10110100. a. What is the ciphertext (in binary form) generated by the encryption of the character ‘M’? (Please show your work.) b. How is the plaintext for this encrypted J recovered? (Please...
Describe how a policy to expand medicare drugs/medicine coverage could be implemented to improve the United...
Describe how a policy to expand medicare drugs/medicine coverage could be implemented to improve the United States' health care system, using the policy cycle. How would this policy go through the 5 steps of the cycle and explain in detail how it becomes a law? What happens in the legislative branch ( house and senate) through the executive branch including implementation, and what are the potential legal implications up to the Supreme Court?
Write a C program that reads a file and reports how many lines, words, and characters...
Write a C program that reads a file and reports how many lines, words, and characters appear in it. For the purpose of this program, a word consists of a consecutive sequence of any characters except white space characters. For example, if the file lear.txt contains the following passage from King Lear, Poor naked wretches, wheresoe’er you are, That bide the pelting of this pitiless storm, How shall your houseless haeds and unfed sides, Your loop’d and window’d raggedness, defend...
4. You manage a crew of 160 workers who could be assigned to make either of...
4. You manage a crew of 160 workers who could be assigned to make either of two products. Product A requires two workers per unit of output. Product B requires four workers per unit of output. a) Write an equation to express the combinations of products A and B that could be produced using exactly 160 workers. b) Measuring the quantity of product A on the horizontal axis and the quantity of product B on the vertical axis, use vertical...
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
Create a program in C that counts the number of characters in a word when a...
Create a program in C that counts the number of characters in a word when a user inputs a string. Use stdin to read an input string. For example, if a user inputs: “The dog is good” the output should be a= [The], b=3 a= [dog], b=3 a= [ is], b=2 a= [good], b=4 a= [ ], b=0000 Take into account EOF. If an EOF is reached at the end of the string then the output should be 0000. (example...
A DNA strand is represented by a string of the characters A, C, G, and T,...
A DNA strand is represented by a string of the characters A, C, G, and T, each of which represents a nucleotide. Each nucleotide has its complement as indicated by this Ruby hash: NUCLEOTIDE_COMPLEMENT = { 'A' => 'T', 'T' => 'A', 'C' => 'G', 'G' => 'C' } The reverse-complement of a DNA string is a new string in which each nucleotide is replaced by its complement and the string is reversed. Reverse-complements are important in bioinformatics since a...
Given the following: Y= C + I + G. C= 50 + 0.8Yd I= 160 G=...
Given the following: Y= C + I + G. C= 50 + 0.8Yd I= 160 G= 150, T = 200 Determine the equilibrium level of output (Y). Calculate Yd, C, S. Calculate the expenditure\ tax multiplier. Now suppose that the potential GDP equals 1100, By how much would government spending\ tax need to change to close the gap?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT