How do I pack to integer values in a double ?
-
what about using union ?
union U {
double _d;
int _i[2];
};
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
Thank you for your reply sir, But I do not want an union :(. The matter is, You have a function like this. Imagine you cannot change it's params. It's built by someone and it's used in numerous instances.
void testDouble(double d) { cout< Now you say , testDouble(2143250); it prints 2143250. Now I want to send two integer values to this function for other reason. I have two numbres, 1000, 2000. these are ints so takes only 4 bytes. `double 00000000000000000000.....64 now 0000000..32 | 0000.......32 is my idea.` But how do I do that? So that in the function, I can do like, void testDouble(double d) { cout<<(HIGHER32)d; cout<<(LOWER32)d; } get me now?
-
Thank you for your reply sir, But I do not want an union :(. The matter is, You have a function like this. Imagine you cannot change it's params. It's built by someone and it's used in numerous instances.
void testDouble(double d) { cout< Now you say , testDouble(2143250); it prints 2143250. Now I want to send two integer values to this function for other reason. I have two numbres, 1000, 2000. these are ints so takes only 4 bytes. `double 00000000000000000000.....64 now 0000000..32 | 0000.......32 is my idea.` But how do I do that? So that in the function, I can do like, void testDouble(double d) { cout<<(HIGHER32)d; cout<<(LOWER32)d; } get me now?
wait, you want to merge 2 ints into a double, or split a double into 2 ints ? BTW be careful, sizeof(int) == 4 only on 32 bits plateforms !
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
wait, you want to merge 2 ints into a double, or split a double into 2 ints ? BTW be careful, sizeof(int) == 4 only on 32 bits plateforms !
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
Thank you for your reply sir, But I do not want an union :(. The matter is, You have a function like this. Imagine you cannot change it's params. It's built by someone and it's used in numerous instances.
void testDouble(double d) { cout< Now you say , testDouble(2143250); it prints 2143250. Now I want to send two integer values to this function for other reason. I have two numbres, 1000, 2000. these are ints so takes only 4 bytes. `double 00000000000000000000.....64 now 0000000..32 | 0000.......32 is my idea.` But how do I do that? So that in the function, I can do like, void testDouble(double d) { cout<<(HIGHER32)d; cout<<(LOWER32)d; } get me now?
int main(int argc, char* argv[])
{
__int32 i[2];
i[0] = 1000;
i[1] = 2000;double d = 0; d = \*(double\*)&i\[0\]; printf("%f\\n", d); \_\_int32 \*o; o = (\_\_int32\*)&d; printf("%d %d\\n", o\[0\], o\[1\]); return 0;
}
of course, anyone doing something like this would end up in the Daily WTF, for sure.
-
How do I pack two integer values in a double ? i.e
int x=1000; int y=2000; double z;
now I want the first four bytes to be occupied by x and the next 4 by y in Z How do I do that? any shift operators would help? please tell me how do I pack & unpack it?Is this what you are after:
int int
/-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-\
| | | | | | | | | | | | | | | | |
\-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-/
double
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Is this what you are after:
int int
/-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-\
| | | | | | | | | | | | | | | | |
\-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-/
double
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
lol, David, are you moking at newbies ? :rolleyes:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
int main(int argc, char* argv[])
{
__int32 i[2];
i[0] = 1000;
i[1] = 2000;double d = 0; d = \*(double\*)&i\[0\]; printf("%f\\n", d); \_\_int32 \*o; o = (\_\_int32\*)&d; printf("%d %d\\n", o\[0\], o\[1\]); return 0;
}
of course, anyone doing something like this would end up in the Daily WTF, for sure.
-
lol, David, are you moking at newbies ? :rolleyes:
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
Moking? Do you mean mocking? No, I was just trying to clarify what the intent was by using a visual.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Is this what you are after:
int int
/-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-\
| | | | | | | | | | | | | | | | |
\-+-+-+-+-+-+-+-|-+-+-+-+-+-+-+-/
double
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Moking? Do you mean mocking? No, I was just trying to clarify what the intent was by using a visual.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
DavidCrow wrote:
Moking? Do you mean mocking?
indeed i was. but that's true also that pictures are more clear than words sometimes...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
int main(int argc, char* argv[])
{
__int32 i[2];
i[0] = 1000;
i[1] = 2000;double d = 0; d = \*(double\*)&i\[0\]; printf("%f\\n", d); \_\_int32 \*o; o = (\_\_int32\*)&d; printf("%d %d\\n", o\[0\], o\[1\]); return 0;
}
of course, anyone doing something like this would end up in the Daily WTF, for sure.