Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

replace arithmetic operation the bitwise operation: for Case A and Case S. /* This allows the user to set or modify short and long integers

replace arithmetic operation the bitwise operation:

for Case A and Case S.

/* This allows the user to set or modify short and long integers and then examine the results in both decimal and binary format. Programmer: Henry Walker, Grinnell College Written in C by Henry Walker (January 28, 2005) Last revised by Henry Walker (January 30, 2005) print_binary revised by Jerod Weinman (January 4, 2019) */ #include void print_binary (int digits, int number); int main (void) { short short_int = 1; int inte = 1; int number; char option; printf (" "); printf ("This program allows experimentation with different sizes of integers "); printf ("Initial integer values: decimal binary "); printf (" Short (16-bit) integer:%13hd ", short_int); print_binary (16, short_int); printf (" "); printf (" Regular (32-bit) integer:%13d ", inte); print_binary (32, inte); printf (" "); while (1) { printf ("Menu Options "); printf (" I - initialize each number to a value you have entered "); printf (" A - add 1 to each integer "); printf (" S - subtract 1 from each number "); printf (" M - multiple each number by 2 "); printf (" D - divide each number by 2 "); printf (" Q - Quit "); printf ("Enter option: "); scanf(" %c", &option); switch (option) { case 'i': case 'I': printf (" Enter value that will be assigned to each integer: "); scanf ("%d", &number); short_int = (short) number; inte = number; break; case 'a': case 'A': short_int += (short) 1; inte += 1; break; case 's': case 'S': short_int -= (short) 1; inte -= 1; break; case 'm': case 'M': short_int *= (short) 2; inte *= 2; break; case 'd': case 'D': short_int /= (short) 2; inte /= 2; break; case 'q': case 'Q': printf ("Program terminated "); return 0; break; default: printf ("Unrecognized option -- please try again "); continue; } // switch printf ("Resulting integer values decimal binary "); printf (" Short (16-bit) integer:%13hd ", short_int); print_binary (16, short_int); printf (" "); printf (" Regular (32-bit) integer:%13d ", inte); print_binary (32, inte); printf (" "); } // while(1) } // main void print_binary (int digits, int number) { /* this function prints the bit representation of number, assuming that digits gives the number of bits in the original declaration of number when called with short ints, digits should be 15 (at least on Pentium 4 machines) when called with regular ints, digits should be 32 */ for (int position = digits-1 ; position>= 0 ; position--) printf ("%X", (number>>position) & 1 ); } // print_binary

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

Write an elaborate note on marketing environment.

Answered: 1 week ago

Question

=+ 2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago

Question

=+ what roles should government play in them ?

Answered: 1 week ago

Question

=+ Why do we have markets and, according to economists,

Answered: 1 week ago