hi
if a person has to access individual bits of an array ( unsigned long : 64; ) then how does one go about doing that?
thankyou
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.
"...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
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.
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.
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
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.
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.
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
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
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.
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
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.
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().