When the bitOrder is LSBFIRST, this function sends data from LSB. It sends the 0th bit of val by calculating bitwise AND of val and 1. Then shifts right by 1 bit to make next bit to be the 0th bit of val.
When the bitOrder is MSBFIRST, this function sends data from MSB. It sends the 7th bit of val by calculating bitwise AND of val and 128(= 0B10000000). Then shifts left by 1 bit to make next bit to be the 7th bit of val.
/*
Copyright (c) 2016 garretlab.
Added source code explanation by garretlab.
*//*
wiring_shift.c - shiftOut() function
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/