Clean code with typedef extraction
This commit is contained in:
parent
290e3ea85e
commit
1a0b36e390
1 changed files with 10 additions and 9 deletions
|
@ -6,6 +6,15 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
Int value : 31;
|
||||||
|
Int signal : 1;
|
||||||
|
} int_with_msb;
|
||||||
|
Int signed_int;
|
||||||
|
} SignedInt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will get the most significant bit of the Int value. If the most significant bit is 1 then the number is
|
* This will get the most significant bit of the Int value. If the most significant bit is 1 then the number is
|
||||||
* 0x11111111 --> equals to -1 integer
|
* 0x11111111 --> equals to -1 integer
|
||||||
|
@ -25,15 +34,7 @@ inline Int msb(Int value)
|
||||||
*/
|
*/
|
||||||
inline Int msb2(Int value)
|
inline Int msb2(Int value)
|
||||||
{
|
{
|
||||||
typedef union {
|
SignedInt sint = {.signed_int = value};
|
||||||
struct
|
|
||||||
{
|
|
||||||
Int v : 31;
|
|
||||||
Int signal : 1;
|
|
||||||
} int_with_msb;
|
|
||||||
Int sint;
|
|
||||||
} SInt;
|
|
||||||
SInt sint = {.sint = value};
|
|
||||||
return sint.int_with_msb.signal;
|
return sint.int_with_msb.signal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue