Why does this code lead to 0?

I have the following code

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <stdint.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    uint32_t Ex;
    Ex=(x<<1)>>24;
    cout<<Ex<<endl;
    return 0;
}

but does it give 0 for any value of x?

My task is as follows:

Computation of the biased exponent Ex of a binary32 datum x.
+3
source share
2 answers

It is not that you get zero for "any x value", but get a zero value for any positive x value less than 0x01000000 (this is 16777216).

None of this helps with the explanation of "biased binary database exponent32." This is similar to a 32-bit floating point number (IEEE) metric. You should probably worry about the credibility of the submission, among other things.

+2
source

You get zero because you are right by shifting 24 bits that shift your significant bits from the end and replace them with zeros on the left.

+1

Source: https://habr.com/ru/post/1755435/


All Articles