I'd like to understand how bit shifting works in C / C ++ . I would also like to understand how the processor performs the calculations and how it handles all of this.
I have some examples in C / C ++ :
void USART_Init(unsigned int ubrr0){
UBRR0H = (unsigned char)(ubrr0>>8); //Ajusta a taxa de transmissão
UBRR0L = (unsigned char)ubrr0;
UCSR0A = 0;
UCSR0B = (1<<RXEN0)|(1<<TXEN0); //Habilita a transmissão e a recepção
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00); //modo assíncrono, 8 bits de dados, 1 bit de parada, sem paridade
}
I would also like to understand the difference between < and > > .
Edit
int x = 1;
x = (x << 8);
x
will be 0001 0000 0000
?
What happens if I "exceed" the number of bits of a variable? Example:
int x = 1;
//Representação na memória:
//{4º byte} {3º byte} {2º byte} {1º byte}
//0000 0000 0000 0000 0000 0000 0000 0001
x = (x << 50); //Como ficaria?
Edit 2:
What operations does the processor do to make the value:
int x = 1; //Corresponde a 0000 0001
Stay this way in memory:
int x1 = (x << 1); //Corresponde a 0000 0010
How does he figure it out? Does it store in a temporary "variable" (register) and then return the original position? Do you do any mathematical calculations? (what?) or is it just memory manipulation?