Thread: PC architecture

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    18

    PC architecture

    Hey how do u find out whether you have a 32bit or 64bit machine easily.
    I am currently running ubuntu btw.

    I ask because this program:
    Code:
    int main ()
    {
        unsigned long long int test;
    
        test = 0xFFFFFFFF;
        /* i get a warning if i make store a larger value */
        /* although it does display the larger value (from the printf) */
        printf( "%lld\n", test );
        
        printf( "sizeof( unsigned long long int ) = %d\n", sizeof(unsigned long long int) );
        printf( "sizeof( long int ) = %d\n", sizeof(long int) );
        printf( "sizeof( double ) = %d\n", sizeof(double) );
        printf( "sizeof( char ) = %d\n", sizeof(char) );
        printf( "sizeof( int ) = %d\n", sizeof(int) );
        
        return 1;
    }
    has been giving me this output:

    4294967295
    sizeof( unsigned long long int ) = 8
    sizeof( long int ) = 4
    sizeof( double ) = 8
    sizeof( char ) = 1
    sizeof( int ) = 4
    any ideas why the 'long int' and 'int' have the same size?
    and why even thoe the long long int is 8 bytes = 64 bits i can't/warns me not to store values greater then 0xFFFFFFFF?

    Thanks Nick

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Hey how do u find out whether you have a 32bit or 64bit machine easily.
    You can't.
    You have to find some implementation specific API call to find that out.

    The compiler writer is free (to an extent) in how they represent the underlying machine.
    Take for example TurboC with it's 16 bit integers which runs passably on a 32 bit machine. It probably manages on a 64 bit machine as well. Doing sizeof(int) using that compiler will tell you nothing.

    > unsigned long long int test;
    Can be implemented in software on any sized machine, it doesn't depend on the hardware. Naturally, it will be a lot more efficient if your machine is 64 bit, but a lack of it doesn't stop the compiler writer from supporting it.

    > i get a warning if i make store a larger value
    Look up your suffixes
    Code:
    test = 0xFFFFFFFFFFFFFFFFull;
    > any ideas why the 'long int' and 'int' have the same size?
    Because the standard allows it.
    The standard states that all types have a minimum capability. Some DSP chips for example have 32bit char, short, int and long!
    Because historically, int has always been the same size as either the 'short' or the 'long'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    Hey, thanksfor your help, i though i could work out the problem i'm having with the answers to the questions i asked but i can't.

    My aim is to create a data structure with 100+ bits that i want to use bitwise operators on. I have been led to believe that a long long int is 64 bits. However when i impliment it, it behaves like it is only 32bits long.

    Note i'm using a struct
    Code:
    struct bitwiseArray
    {
        unsigned long long int high;
        unsigned long long int low;
    };
    with the aim of using only the first 100 bits

    Look up your suffixes
    please refresh my memory on what a suffix is or please tell me how to create a 64bit number and verify it.

    Thanks again

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    >please refresh my memory on what a suffix is....
    I already showed you an example.
    If you want the full set, read a book.

    > My aim is to create a data structure with 100+ bits that i want to use bitwise operators on
    Like
    Code:
    #include <limits.h>
    
    //
    
    unsigned char bits[(100/CHAR_BIT)+1];
    CHAR_BIT tells you how many bits there are in a char
    You can work out the number of bits in every other type by using this and sizeof.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2006
    Location
    Great India
    Posts
    24
    Quote Originally Posted by Shotgun
    My aim is to create a data structure with 100+ bits that i want to use bitwise operators on. I have been led to believe that a long long int is 64 bits. However when i impliment it, it behaves like it is only 32bits long.

    Note i'm using a struct
    Code:
    struct bitwiseArray
    {
        unsigned long long int high;
        unsigned long long int low;
    };
    with the aim of using only the first 100 bits
    What do you mean by data structure of 100+bits ? DID you mean that the size of structure will be more than 100bits ? or semething else.

    Please explain

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    a have to compare arrays of up to 100 elements against each other, i and going to have to do several types of comparisons and many times so i though that using bitwise operators would massively increase speed. Hence i need a data structure with 100 bits.

    Thanks

  7. #7
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Shotgun
    a have to compare arrays of up to 100 elements against each other, i and going to have to do several types of comparisons and many times so i though that using bitwise operators would massively increase speed.
    Or greatly bog it down. Why don't you describe the problem in greater detail rather than describing issues with a presumed solution?

    That is, if you want the best answer to
    How do I do X?
    Don't ask
    How do I do Y (because I think it's the best solution for X -- even though I'm not sure how to do X)?
    Just ask how to do X.

    And of course: "premature optimization is the root of all evil".
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    Ok, I have a project where we have to solve the Minimisation of Open Stacks Problem (MOSP).

    In a manufacturing environment storage space is often quite limited and needs to be carefully managed. The Minimisation of Open Stacks Problem aims to determine a sequence in which products are manufactured that minimises the number of open stacks and hence limits the amount of storage space required. An stack is opened each time a product is manufactored for a customer (that doesn't already have a stack) and only closed after everything that customer ordered has been made.

    The maximum amount of products and customers i will be dealing with is 100. We have spent a while discussing how to efficently determine a product manufactoring sequence that has an optimal (low) maximum number of stacks open. Some of these methods include determining if some products are sub-sets of other products (schedual them together) or if the problems can be divided into smaller problems when they share no common customers (partitioning).

    The easiest way to perform these tasks it through the use of AND, OR and NOT operations. Hence i though that bitwise operators would efficiently beable to fullfil these aims.

    Hope that makes sense

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So go for a nice clean design which has a nice clean interface to this problem, and actually implement it in an obvious way.

    Have you done a search for algorithms? Picking the right algorithm is the single biggest optimisation you will make, and it doesn't even involve writing any code.

    When you have something working, then you're in a position to actually evaluate performance.

    You may find that the performance is adequate to start with, and you haven't busted a gut optimising something which didn't need it in the first place.
    Or you may find the bottleneck is elsewhere, and you haven't busted a gut optimising the wrong thing.

    Also, since you have something which works, then you can easily see whether anything you try a) makes it quicker and b) still works.

    Lets face it, a few hundred something's isn't really going to tax the average desktop machine unless you're intent on trying every possible combination.

    BTW, there will be sod-all difference between
    Code:
    struct bitwiseArray
    {
        unsigned long long int high;
        unsigned long long int low;
    };
    //
    // test foo.low and foo.high
    and
    Code:
    unsigned long bits[(100/CHAR_BIT/sizeof(unsigned long))+1];
    //
    // test for ( i = 0 ; i < 4 ; i++ ) test bits[i]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When done right, PC games are amazing
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-13-2008, 05:32 PM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. Reformating PC
    By Zero_X in forum Tech Board
    Replies: 3
    Last Post: 07-09-2006, 04:25 PM
  4. Need help with reformating my pc
    By XunTric in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-22-2005, 04:44 PM
  5. Post you pc pics (mods)
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 03-15-2004, 04:15 PM