Thread: unsigned long : 64;

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    unsigned long : 64;

    hi

    if a person has to access individual bits of an array ( unsigned long : 64; ) then how does one go about doing that?

    thankyou

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Think about how bit-wise operators maybe used in this situation.

    & ( Bitwise and operator ) will assist you. It's used for masking off bits or checking to see if bits are set, etc. Also think about using the shift operators << >> to shift the number left or right respectively. Just play around with that stuff and post something up if you get stuck.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Code:
    unsigned long long bit ( int pos ) {
        return 1ull << pos;
    }
    unsigned long long set ( unsigned long long val, int pos ) {
        return val | bit(pos);
    }
    unsigned long long clear ( unsigned long long val, int pos ) {
        return val & ~bit(pos);
    }
    bool isset ( unsigned long long val, int pos ) {
        return (val & bit(pos)) != 0;
    }
    bool isclear ( unsigned long long val, int pos ) {
        return (val & bit(pos)) == 0;
    }
    These are the underlying bit-wise operators

    If you want to implement these in some kind of class, where you can do things like value[pos], then that's up to you.
    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.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Just to point out, the above stuff is assuming Little-Endian ordering.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Just to point out:


    unsigned long <var_name>: 64;

    is not an array.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Just to point out, the above stuff is assuming Little-Endian ordering.
    Where?
    I didn't think my examples had an endian issue at all.
    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.

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    They didn't. I was lost, too.


  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Argh, my mistake. Apologies.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    thanks guys

    i have come some way since the last info, but for some reason when i implement this code, i get the following error, (after compile) "The exception unknown software exception (0xc00000fd) occured in the application at location 0x0040b506."
    all help is appreciated
    thanks

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It means you made a mistake
    Post your code for more clues as to where you made a mistake
    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.

  11. #11
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    Here is my code

    i have fixed on part so now i have a stack overflow problem
    [CODE]
    void IP(){
    plaintext part;
    if (part.plaintxtR & 0x14){
    part.plaintxtL |= 0x01;
    }

    }
    [CODE]

  12. #12
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    here is what my pseudo code would look like

    if the 58th bit of the plain-text is turned on
    then turn on the 1st bit of the output-text.

    any ideas for helping me implement this?
    thanks

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    1. Press "Preview post" before submit, to check you used the tags properly

    2. Post more code, ideally a complete program which demonstrates the problem. There's nothing in what you post which can cause the problem you see
    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.

  14. #14
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    ALL my code

    here is my code
    Code:
    #include "iostream.h"
    
    struct key64 {
    
    	unsigned key64L32 : 32;
    	unsigned key64R32 : 32;
    };
    
    struct key56 {
    
    	unsigned key56L28 : 28;
    	unsigned key56R28 : 28;
    };
    
    struct plaintext {
    
    
    	unsigned long plaintxtR;
    	unsigned long plaintxtL;
    
    
    	unsigned p48La : 28;
    	unsigned p48Lb : 28;
    
    
    	unsigned p48Ra : 28;
    	unsigned p48Rb : 28;
    
    
    };
    
    void IP(){
    plaintext part;
    part.plaintxtL |= 0x001;
    }
    
    int keep;
    
    void main(){
    plaintext part;
    cout<< part.plaintxtL<<endl<<endl;
    IP();
    cout<< part.plaintxtL<<endl;
    cin >> keep;
    }

  15. #15
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    Posts
    128
    For one, you'll need to make part a global variable if you want to modify it in IP().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. sorting using pointer to pointer not working
    By eager2no in forum C Programming
    Replies: 17
    Last Post: 09-21-2008, 12:52 AM
  3. Unsigned long long to something longer
    By JFonseka in forum C Programming
    Replies: 18
    Last Post: 05-26-2008, 07:34 AM
  4. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 12:43 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM