Berkeley CSUA MOTD:Entry 14688
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/09 [General] UID:1000 Activity:popular
7/9     

1998/9/28-29 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages] UID:14688 Activity:kinda low
9/27    I'm trying to output the binary representation of a ieee754 double
        in c/c++.  I'm using union { double x; long y; } and then
        shifting iteratively with a value.y >> i and then masking it with
        a value.y & 0x1 but that doesn't seem to work.  Any suggestions?
        \_ first problem:  a double is probably larger in size than a long
           on your architecture.  are you sure your compiler is doing ieee754
           doubles?  what you described is very dependent on what you're using.
        \_ printf("%08x\n", * (long *) &x);
        \_ printf("%qx\n", *(long long *) &x) is what you want on soda, where
           a double is 64 bits and a long is 32.  Other machines will vary.
        \_ Why not use a char array in your union?  That way you only have
           the length of the double to worry about.
           \_And the endian-ness.
2025/07/09 [General] UID:1000 Activity:popular
7/9     

You may also be interested in these entries...
2012/7/29-10/17 [Computer/SW/Languages] UID:54447 Activity:nil
7/23    Hey mconst, check this out:
        int main()
        {
            int i_value   = 16777217;
            float f_value = 16777217.0;
            printf("The integer is: %d\n", i_value);
	...
2012/7/23-29 [Computer/SW/Languages] UID:54443 Activity:nil
7/23    Hey mconst, check this out:
int main()
{
    int i_value   = 16777217;
    float f_value = 16777217.0;
    printf("The integer is: %d\n", i_value);
	...
2012/3/15-6/1 [Computer/SW/Languages, Computer/SW/OS/Windows] UID:54340 Activity:nil
3/15    Why does MS put double-quotes around the '8' in Windows Server 8, like
        the following?
        - Windows 8
        - Windows Server "8"
        \_ Because when they didn't do it, code didn't see the '\0'
           and went over?  Looks better than '8','\0' *shrug*
	...
2011/3/7-4/20 [Computer/SW/Languages/C_Cplusplus] UID:54056 Activity:nil
3/7     I have a C question.  I have the following source code in two identical
        files t.c and t.cpp:
                #include <stdlib.h>
                int main(int argc, char *argv[]) {
                  const char * const * p1;
                  const char * * p2;
	...
2010/1/26-2/8 [Computer/HW/Memory] UID:53665 Activity:nil
1/26    What's a good motherboard I can get that will fit in a 1U
        case, with sata connectors, gig-e ethernet, and lots of
        slots for RAM?  I also don't want to have to use expensive
        double buffered RAM.  Can you tell I havne't bought a PC in
        years?  thanks.
        \_ Buy a mac. Haven't you heard? if you don't buy a Mac people
	...
2009/4/30-5/6 [Computer/Theory] UID:52923 Activity:nil
4/30    Sorting question!  I have n sorted arrays of doubles.  What's the
        fastest way to sort them into 1 big sorted array?
        \_ as mentioned below: you are describing one half of mergesort
        \_ You really have to ask this question?
           \_ You don't know either, huh?
        \_ If three are n sorted arrays of m doubles each, I think the fastest
	...