|
|
View previous topic :: View next topic |
Author |
Message |
zjcheah Guest
|
shift_left, shift_right definitive guide! |
Posted: Wed Dec 21, 2005 9:56 pm |
|
|
I've been playing around with these 2 commands, but something puzzles me. I will post a few cases below. Hope someone will enlighten me.
Code: | char Array[3]={0b10110111, 0b01010101, 0b11110000};
for (pixel=0;pixel<24;pixel++){
output_bit(data, shift_left(&Array[0],3,0));
}; |
will shift Array[2] FIRST, MSB FIRST. The output will be 11110000,01010101,10110111 from left to right.
a shift_right command however will shift Array[0] FIRST, LSB FIRST. The output will be 11101101,10101010,00001111 from left to right.
Now on to the tricky part:
I want to shift not by 8 bits (a byte), but by 6 bits. I shifted bits into a data structure, then output them to observe what has happened.
However the I shifted bits into a data structure, then output them to observe what has happened.
Currently I'm confused to how the pointer is moving around to be able to create the pattern in the data structure.
Code: | typedef struct {
char line[3];
} dpixelLine;
char temp;
dpixelLine dataLine;
int counter,bitCounter;
for(counter=0;counter<3;counter++){
temp=Array[counter];
for(bitCounter=0;bitCounter<6;bitCounter++) {
shift_left(&dataLine,3,shift_right(&temp,1,0));
}
} |
Now if I use the same outtput_bit command above to output dataLine:
Code: | output_bit(data2, shift_left(&dataLine,3,0)); |
will produce an output 00000011,10111010,10000011 from left to right.
It is noteworthy here that after the first 6 zeroes(the zeroes are due to the data structures being filled with zeroes initially, i didn't include that code here as it is irrelevant) the pattern starts; that is 11,1011010,10000011 translates to the bits of the Array[] that are actually shifted into the dataLine struct.
Following the logic of shift_left and shift_right as explained in the earlier part, we deduce that dataLine's contents must be (10000011,10111010,00000011)
Can anyone give me a good explanation why ?[/code] |
|
|
zjcheah Guest
|
another thought |
Posted: Wed Dec 21, 2005 10:14 pm |
|
|
Perhaps where to start would be answering why (10000011,10111010,00000011) those zeroes are there since a shift_left should move the bits towards the MSB side. |
|
|
zjcheah Guest
|
? |
Posted: Thu Dec 22, 2005 8:51 pm |
|
|
No one has any idea?
or everyone is busy preparing for Christmas? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Thu Dec 22, 2005 9:06 pm |
|
|
I found a bug in PCH 3.229 where shifts across a 16 bit boundary are broken. I have run out of my support window so there was no value in posting a bug report. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
zjcheah Guest
|
Thanks |
Posted: Fri Jan 06, 2006 7:24 pm |
|
|
Thanks for that information, i have now restructured my algorithm to only shift 8 bit variables. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|