So I'm writing a program that is supposed to output the binary representations of numbers using a bitwise operator and a mask. The extra credit portion(Which we were told we had to do.) Asks us to change from the integer operations we were doing and switch to floating point. The issue I am running into is getting the insertion operator to continue after it encounters a non integer (a period). It immediately takes the integer preceding the . and runs the operations (Then terminates because my loop gets a input to see if it should continue and a period is not 'Y') Basically how do I cin a number like 3.14159.
The point of the exercise is to find out how my system stores floating point decimals in binary form. While I know that it is IEEE standard to store it as 1 bit sign, 10 bits exponent, and 22 bits mantissa, I have to show it. The if (num1 & mask) does the work in this case, but unfortunately it does not work when using floats and integers. Another person on another board mention that you had to do a union when comparing floats and integers in bitwise operations, but I haven't been able to grasp that concept just yet. Anyone have any pointers?
Thanks, while that is I'm sure technically going to show me the answers, after talking to the professor I need to trick the compiler into thinking that it is using a integer by using a pointer. I just as clueless now I was before but, atleast I have a starting point.
So if I am reading this correctly the print_bits function goes by printing the the input (Floating number in this case) then declares a constant char pointer called p and assigns it the address of n using a reinterpret_cast to get the address of a fundamentally different class (float) to be a address contained in pointer of the const char type. then for i = 0 to 1 less then the size of n you do an operation that I don't understand. Could you break down what is happening in line 10 for me?