hi
if a person has to access individual bits of an array ( unsigned long : 64; ) then how does one go about doing that?
thankyou
Printable View
hi
if a person has to access individual bits of an array ( unsigned long : 64; ) then how does one go about doing that?
thankyou
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.
These are the underlying bit-wise operatorsCode: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;
}
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.
Just to point out, the above stuff is assuming Little-Endian ordering.
Just to point out:
unsigned long <var_name>: 64;
is not an array.
> 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.
They didn't. I was lost, too.
:confused:
Argh, my mistake. Apologies.
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
It means you made a mistake
Post your code for more clues as to where you made a mistake
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]
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
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
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;
}
For one, you'll need to make part a global variable if you want to modify it in IP().