Question

In: Computer Science

Language: C++ In your main(), use printf() to print out the floating point values for some...

Language: C++
In your main(), use printf() to print out the floating point values for
   some hex data.
   a. To print 1.0, do
         printf("One:      %f\n",0x3FF0000000000000);
      The compiler will give you a warning about the argument being a different
      type than the format, but that is ok.
   b. To print 2.0, do
         printf("Two:      %f\n",0x4000000000000000);
      Remember, to multiply by two, you just add one to the exponent.
   c. Print 4.0, 8.0, and 16.0 (with nice labels, of course).
   d. We can also go the other way. To divide by two, just decreas the 
      exponent by one.  So for 1/2, do
         printf("Half:     %f\n",0x3FE0000000000000);
   e. Print 1/4, 1/8, 1/16.
   f. Negative values have a 1 in the leading bit instead of 0.  A leading 1
      in the bits for a hex digit has value 8, so -1.0 is BFF0000000000000.
      So to print -1.0, do
         printf("Neg One:      %f\n",0xBFF0000000000000);
   g. Print -2, -4, -8, -1/2, -1/4, -1/8 (with nice labels, of course).

Solutions

Expert Solution

Comment if there are any issues, queries or if you need any changes to be made.

Code:

#include <iostream>
int main() {
        printf("One:      %f\n", 0x3FF0000000000000);
        printf("Two:      %f\n", 0x4000000000000000);
 
        //401 is the new exponent
        //4 in hex is 0x4010000000000000
        printf("Four:      %f\n", 0x4010000000000000);
        //exponent 402
        printf("Eight:      %f\n", 0x4020000000000000);
        //exponent 403
        printf("Sixteeen:      %f\n", 0x4030000000000000);
 
        //print 1/2
        printf("Half:     %f\n", 0x3FE0000000000000);
        //subtract 1 from exponent of 1/2
        //new exponent 3FD for 1/4.
        printf("a Fourth:     %f\n", 0x3FD0000000000000);
        // 1/8 subtract 1 from exponent of 1/4
        printf("an Eighth      %f\n", 0x3FC0000000000000);
        // 1/16 subtract 1 from exponent of 1/8
        printf("one Sixteenth      %f\n", 0x3FB0000000000000);
 
        //-1
        printf("Neg One:      %f\n", 0xBFF0000000000000);
        //-2
        printf("Neg Two:      %f\n", 0xC000000000000000);
        //-4, add 1 to exponent of -2
        printf("Neg Four:      %f\n", 0xC010000000000000);
        //-8, add 1 to exponent of -4
        printf("Neg Eight:      %f\n", 0xC020000000000000);
        // -1/2
        printf("Neg Half:      %f\n", 0xBFE0000000000000);
        // -1/4
        printf("Neg a Fourth:      %f\n", 0xBFD0000000000000);
        // -1/8
        printf("Neg an Eighth:      %f\n", 0xBFC0000000000000);
 
        return 0;
}
 

Code Screenshot:

Output:


Related Solutions

C programming #include <stdio.h> #include <math.h> int main() { printf("============== Problem #1 =================\n"); printf("This should print...
C programming #include <stdio.h> #include <math.h> int main() { printf("============== Problem #1 =================\n"); printf("This should print down from 2 to 0 by 0.1 increments\n"); float f = 2.0; while (f != 0) { printf("%0.1f\n",f); f = f - 0.1; } printf("============== Problem #2 =================\n"); printf("This should find that the average is 5.5\n"); int total_score = 55; int total_grades = 10; double avg = total_score/total_grades; printf("Average: %0.2f\n",avg); printf("============== Problem #3 =================\n"); printf("If the population increases by 2.5 people per second, how...
In coding language C, Write a program in which will use floating point variable (input=232.346) and...
In coding language C, Write a program in which will use floating point variable (input=232.346) and print out: 1. scientific notation form of input. 2. floating point form of input with total width 12 (default right aligned). 3. floating point form of input with total width 12 (default right aligned) and add 0s for unused space. 4. floating point form of input with total width 12 (left aligned). 5. floating point form of input with total width 12 (default right...
Design a C program to print out the unsigned char (integer) values of the 4 bytes...
Design a C program to print out the unsigned char (integer) values of the 4 bytes in sequential order (i.e., the first byte is printed first). Using the code framework provided below, the printing is done by the function void byte_value(int *), in which only pointer variables can be declared and used. #include <stdio.h> ​ void byte_value(int *); ​ int main() { int n = 1; byte_value(&n); printf("Enter an integer: "); if (scanf("%d", &n) == 1) byte_value(&n); return 0; }...
Write an assembly language program that will print out the message of your choosing #NOTE #write...
Write an assembly language program that will print out the message of your choosing #NOTE #write in a simple way, so that i can execute it from command window using masm
Convert the decimal floating point value 8.125 to a 12 bit binary floating point value. Use...
Convert the decimal floating point value 8.125 to a 12 bit binary floating point value. Use a sign bit, 3 bits (excess 3) for the exponent and an 8 bit significand. Enter just a 12 digit binary value ( e.g. 0 000 11110000 ) spaces ignored.
c++ Write a program that print stars, Max and Min values. It should use the following...
c++ Write a program that print stars, Max and Min values. It should use the following functions: (2 pts) int getNum ( ) should ask the user for a number and return the number. This function should be called by main once for each number to be entered. Input Validation: Do not accept numbers less than -100. (2 pts) void printStars ( int n ) should print n number of stars. If n is less than 0, display "Invalid" message...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values...
MUST BE DONE IN C (NOT C++) Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything
IN C LANGUAGE This program will read in a series of strings and print only the...
IN C LANGUAGE This program will read in a series of strings and print only the consonants (including Y) until the word "stop" appears. No string will be longer than 100 characters. A consonant is any letter that is not a vowel. Don't forget to follow the standard read pattern! Examples Enter a string: Hello Hll Enter a string: World! Wrld Enter a string: 123! Enter a string: stop Enter a string: stop
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
//using c fixing the error to make a correct print-out. #include <stdio.h> int main(void) { unsigned...
//using c fixing the error to make a correct print-out. #include <stdio.h> int main(void) { unsigned int a = 1000; signed int b = -1; if (a > b) printf("%d is more than ", a); printf("%d\n", b); else printf("%d is less or equal than ", a); printf("%d\n", b); return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT