Shift what and how? Do you think of the array as an integer > 32 bits that should be shifted?
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
array contains binary number of length-32!!!! how to do shifting of those binary numbers!!!![it has to shift from left to right].
int p[32]={1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0}
how to do shifting of this array?
Last edited by hemanth144; February 16th, 2012 at 04:05 PM.
array contains binary number of length-32!!!! how to do shifting of those binary numbers!!!![it has to shift from left to right].
int p[32]={1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0}
how to do shifting of this array?
for(i=0;i<31;i++)
{
p[i]=p[i-1];
cout<<p[i];
} // if i use this code the bits be shifted from left to right?
Why not write the program and see if it works?
Seriously, I can't believe the number of new posters who either refuse to debug their code and want one of us to do that job for them, or they can't just write their program and then see if it works or not.
for(i=0;i<31;i++)
{
p[i]=p[i-1];
cout<<p[i];
} // if i use this code the bits be shifted from left to right?
As far as I can tell, the code is going to crash immediately on the first iteration because of index being out of bounds. And even started from 1, the code just replicates the first array element (not bits!) through the rest of the array. So the answer is: No they won't.
So what are you shifting? Elements in array or their content?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...
array contains binary number of length-32!!!! how to do shifting of those binary numbers!!!![it has to shift from left to right].
int p[32]={1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0}
how to do shifting of this array?
Exclamation points don't add clarity to your post, no matter how many you use. Since nobody understood your question the first time, try rewording it.
Frankly, why is it so impossible to spend a few minutes to write a question that clearly states the issue?
Assuming that you want to shift
int p[32]={1,0,1,1,0,1,0,1,0,0,1,0,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0} from left to right this should do it
Code:
for(int i=1;i<31;i++)
{
p[i]=p[i-1];
}
p[31] = 0;
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Bookmarks