Answered: Unclear moment in sending data on serial

Hi all!

I'm making a programmable load. One of the steps is to make ATmega328 to talk to a MCP4921 DAC via serial interface.
The code that does the actual sending looks like this (courtesy of tronixstuff):

  outputValue = tAmps;
    digitalWrite(10, LOW);
    data = highByte(outputValue);
    data = 0b00001111 & data;
    data = 0b00110000 | data; //or data = 0b10110000 | data; to address the DACb
    SPI.transfer(data);
    data = lowByte(outputValue);
    SPI.transfer(data);
    digitalWrite(10, HIGH);
    delay(10);

I do understand how this code does what it does, except for the "0b" part in the "data = 0b00001111 & data;" line in a line just below it.
If you know please explain :slight_smile:
_

0b means that the value to follow is in binary, not decimal, octal, or hex.

That part takes out the highest 4 bits of data using AND.

Aha! Thanks a lot, that explains it!