rockkaristar
Ominide
1 min. di lettura
Vota 5 / 5

Concetti Chiave

  • Shift involves moving all bits of a binary number left or right, often used to speed up binary multiplication and division.
  • In left shift, bits are shifted left, with vacant positions on the right filled with zeros.
  • In right shift, bits are shifted right, with vacant positions on the left filled with zeros.
  • Rotate implies that bits moved out from one end reappear on the opposite end, preserving the number of bits.
  • The key difference between shift and rotate is that shift discards bits while rotate retains them.
Operazioni sui numeri - Shift e Rotate

Shift
Per shift a sinistra o a destra s’intende lo spostamento di tutte le cifre di un numero binario di una posizione rispettivamente a sinistra o a destra. Di tratta di una procedura frequente all’interno dei calcolatori che, pur non essendo una vera e propria operazione aritmetica, in alcuni casi permette di velocizzare le operazioni di moltiplicazione e divisione binaria.

Esempi:
Left shift Right shift
00101000 00101000
01010000 00010100
10100000 00001010
01000000 00000101

Rotate
Ruotare a sinistra un numero binario di 1bit o di Nbit significa che 1bit o Nbit escono dalla parte sinistra e ricompare dalla parte destra.
Ruotare a destra un numero binario di 1bit o Nbit significa che 1bit o Nbit escono dalla parte destra e ricompare dalla parte sinistra.

Esempi:
Left rotate Right rotate
10110011 10110011
01100111 11011001
11001110 11101100
10011101 01110110

La differenza tra rotazione e shift, è che mentre nel shift il numero binario spostato è eliminato, nella rotazione quel numero ricompare e non viene eliminato.

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community