Why perform bitwise operations here? (SPI FRAM read method) See: https://github.com/adafruit/Adafruit_FRAM_SPI/blob/master/Adafruit_FRAM_SPI.cpp
The following method reads and converts the input to 8 bit. I have several questions concerning its function.

Using addr = 0xFFFF as an example, the method converts the variable to 0xFF. I understand that bits are removed from the end, but surely 65535 != 255. Perhaps relatively, to their max size, but how is this a useful conversion? I might be missing something about bitwise here..

uint8_t Adafruit_FRAM_SPI::read8 (uint16_t addr)
{
 digitalWrite(_cs, LOW);
 SPItransfer(OPCODE_READ); //read memory from fram array (2-byte)
 SPItransfer((uint8_t)(addr &gt;&gt; 8));
 SPItransfer((uint8_t)(addr &amp; 0xFF));
 uint8_t x = SPItransfer(0);
 digitalWrite(_cs, HIGH);
 return x;
}


Correct me if I'm wrong, the casting is to keep sign extension from occurring.

The masking I understand in theory, but do not at all understand its application here.

Finally, it always returns the same value x = 0, why?

I also see there's a write method but no read method. Only read8. Reasoning?
Let's assume addr is 0xbeef. Then, if we break down each operation:

expression             │ value
───────────────────────┼───────
addr                   │ 0xbeef
addr &gt;&gt; 8              │ 0x00be
(uint8_t)(addr &gt;&gt; 8)   │   0xbe
addr &amp; 0xFF            │ 0x00ef
(uint8_t)(addr &amp; 0xFF) │   0xef


So this is essentially breaking down the address into two 8-bit chunks,
and transmitting those chunks individually. It's done like this because
SPI only transmits bytes.


  the casting is to keep sign extension from occurring.


Non, sign extension cannot occur, since addr is an unsigned number.
The casting really serves no useful purpose, other than documenting the
code. It would be done implicitly simply because SPItransfer() takes
an uint8_t argument. The casting could be useful if SPItransfer()
was overloaded with a 16-bit version.


  Finally, it always returns the same value x = 0, why?


No, it returns whatever the call to SPItransfer(0); returns, i.e. the
data sent by the FRAM module.