Question

C language program. How could I use bitwise opreation "and" to two float variable? If it...

C language program.

How could I use bitwise opreation "and" to two float variable?

If it is impossible, please show another way to achieve the same goals.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

It is not possible because there's no such thing as "bitwise operation on floating-point numbers". Bitwise operations in C/C++ work on value-representation of a number. And the value-representation of floating point numbers is not defined in C/C++. Floating point numbers don't have bits at the level of value-representation, which is why you can't apply bitwise operations to them.

You can analyze the bit content of the raw memory occupied by the floating-point number. For that you need to either use a union as suggested below or (equivalently, and only in C++) reinterpret the floating-point object as an array of unsigned char objects, as in

float f = 5;

unsigned char *c = reinterpret_cast<unsigned char *>(&f);

 
Add a comment
Know the answer?
Add Answer to:
C language program. How could I use bitwise opreation "and" to two float variable? If it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help. In language c View Layout References Mailings Program 1 Write a simple invoice generating program...

    Help. In language c View Layout References Mailings Program 1 Write a simple invoice generating program for a pet store as follows: 1- Ask the user for tee tax rate and store it in a float variable. 2- Ask the user for the number of cats being purchased and store the value in an integer variable. 3- Ask the user for the price of one cat and store it in a float variable. 4- Ask the user for the number...

  • using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float...

    using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float number2)that tests whether a floating point number number1is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differingbit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1...

  • C language. I use nano text editor. Make a C program to do one of two...

    C language. I use nano text editor. Make a C program to do one of two things: either print all of the parameters passed to it, or, if one of those parameters is "-h", print a few lines about what the program does. That is, if one of the parameters is "-h", it should not print the parameters, only the "help" message.

  • in c++ Write a program which can add two float vectors (arrays) of any length ?....

    in c++ Write a program which can add two float vectors (arrays) of any length ?. The length ? of the two vectors being added should be the same. The user will enter the length ?. Use the length to control how many times you loop. The result is also a vector.

  • Question 1: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating...

    Question 1: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1 is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differing bit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1 > number2, return...

  • Write a C program that reads in a float constant (use %f in scanf) and displays...

    Write a C program that reads in a float constant (use %f in scanf) and displays its internal representation in hex. Use your program to check your answers to problem 1. Hint: a union is like a struct except that the fields overlap. Hint: the conversion code for hex is %x. union X { int a; float b; }; int main() { union X test; ... ; test.a and test.b refer to same word in memory but have ; different...

  • PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE...

    PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE 11. Initialize a integers in the two-dimensional array testArray to the values 1 through 9 using 1 or more while loops so that the array could be visualized as: 1 2 3 LA 5 6 7 8 9...

  • First, review your C language data types Learn how to use the strtok() function in C language. Th...

    First, review your C language data types Learn how to use the strtok() function in C language. There are plenty of examples on the Internet. Use this function to parse both an example IP address, eg. 192.168.1.15, into four different strings. Next use the atoi() function to convert these into four unsigned char's. (Hint: you will need to typecast, eg unsigned char X-(unsigned char)atoi("234"); Now, if you view a 32 bit number in base 256, the right most column would...

  • Write a program equivalent to the C language assignment statement z = a + (b *...

    Write a program equivalent to the C language assignment statement z = a + (b * c) + (d * e) - (f / g) - (h * i); Use only: (a) Three-address instructions (b) Two-address instructions Please explain the process as clearly as possible. I would like to LEARN how this is done in so little address instructions. Thank you.

  • Prime Number Programing in C Note: The program is to be written using the bitwise operation....

    Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT