14
I would like to understand how the bit offset works in C/C++. I’d also like to understand how the processor performs the calculations and how it handles all 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’d 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 for that value:
int x = 1; //Corresponde a 0000 0001
Stay this way in memory:
int x1 = (x << 1); //Corresponde a 0000 0010
How does it calculate this? Does it store in a temporary "variable" (registrar) and then returns the original position? Do you make any mathematical calculations? (what?) or is it just memory manipulation?
The tone of your questions usually reminds me of this guy...
– pepper_chico
Hahaha, I laughed a lot reading this comic strip. I identified myself a lot. I like to try to understand everything at the hardware level.
– Avelino
Real programmers use Butterflies
– Avelino