Hi,
I am very puzzled, in my code " my_data |= (byte_1<<16);" does not shift byte but when I use code " my_data |= (1<<16);" This works fine, I have value of byte_1 = 1.
when shift by 8 both codes works fine
my_data |= (byte_1<<8); //works fine
my_data |= (1<<8); //works fine
Please make me understand what am I missing?
//----------------------------------------------
unsigned int long my_data=0;
void main()
{
while(1){
char byte_1 = 1; //0b00000001
my_data |= (byte_1<<16); // this shift does not work
// my_data |= (1<<16); // this shift does work
}
}
//-------------------------------------------------------
Best regads
Sunny
Byte shift by 16 does not work whereas 8 works
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: Byte shift by 16 does not work whereas 8 works
Hello,
You have pushed the one "1" out of the scope of byte and then you are OR-ing it with my_data.
When you shift one as constant, you are using signed long int constant four byte in size.
Try shifting:or something like this:
Best regards.
You have pushed the one "1" out of the scope of byte and then you are OR-ing it with my_data.
When you shift one as constant, you are using signed long int constant four byte in size.
Try shifting:
Code: Select all
my_data |= (byte_1<<5); // this shift does not work
my_data |= (1<<5); // this shift does work
Code: Select all
my_data |= (-1<<16);
Re: Byte shift by 16 does not work whereas 8 works
Hi dejan,
Thanks for your response but shift by 8 works fine.
Could you please explain me why?
when shift by 8 both codes works fine
my_data |= (byte_1<<8); //works fine
my_data |= (1<<8); //works fine
Best regards
Sunny
Thanks for your response but shift by 8 works fine.
Could you please explain me why?
when shift by 8 both codes works fine
my_data |= (byte_1<<8); //works fine
my_data |= (1<<8); //works fine
Best regards
Sunny
- dejan.odabasic
- mikroElektronika team
- Posts: 2649
- Joined: 30 Apr 2012 14:20
Re: Byte shift by 16 does not work whereas 8 works
Hello,
You are right, it's working, but it shouldn't and I'll report this behavior to our developers.
If you wish to avoid it, you can use:
Best regards.
You are right, it's working, but it shouldn't and I'll report this behavior to our developers.
If you wish to avoid it, you can use:
Code: Select all
my_data |= (char)(byte_1<<8);