# Help Me Understand Segmented Digit Displays, How HEX>Binary is Used

Newbie playing with an Arduino Uno starter kit, exploring the language and whatnot.

So my kit came with a single digit 7-segment (though really 8-segment due to decimal point) as well as a 4 digit display. Unfortunately they are common anode variety so I couldn’t play with the MAX7219 and 4-digit according to some guides I saw. I wired these up directly to the Arduino board pins.

The sample code came with this array for digits 0-9
byte Numcode[10] = {0xfc, 0x60, 0xda, 0xf2, 0x66, 0xb6, 0xbe, 0xe0, 0xfe, 0xf6}

It all seems so stupidly simple now, that the last two characters are hexadecimal values that can be translated to an 8-bit binary number, and that this string of 8 zeros and ones corresponds to the 8 segments of the display, telling each one to be on or off in order.
E.g., 0xda displays “2”
218 in normal decimal
11011010 in 8-bit binary

8 of the digit segments are arranged:

Displaying a “2” without the decimal point means
A - B - C - D - E - F - G - DP
On-On-Off-On-On-Off-On-Off
1 - 1 - 0 - 1 - 1 - 0 - 1 - 0

Well, in the process of my deciphering how the heck those hexadecimals correlated to the displayed number, I created a table for all possible hex values and their resulting display. The drudgery was accompanied with epiphany, so the meaningless work had some small value. Yes, I hooked up a display and changed the code to actually see every single 0x _ _ hex combination in reality. But I cut my work in half after realizing every other value was just the previous one with the decimal added.
You can ogle the fruits of that labor here

Probably could’ve skipped to this part, but just so we’re on the same page. There’s this part of the code that actually writes the number to the digit. I need help understanding the bitwise math business.

``````    for (j = 0; j < 8; j++)
{
if (Numcode[i] & 1 << j) //at this point i is equal to the typed in number. "&" and "<<" are bitwise math things.
digitalWrite(9 - j, LOW); //turn on something
else
digitalWrite(9 - j, HIGH); //turn off that something
}
``````

Using 2 as an example, so i=2, Numcode[2] means 0xda, which as mentioned is 11011010 in binary.
Why is this getting &1 and then shifted left 0 through 7 times as an if statement, and how is that condition true or false?
“2” ---- 11011010
1 ---- 00000001
2&1 — 00000000 it seems this will always come out false as none of the numcodes have the decimal point “on”
<<j ?

I’m not understanding the part of taking the binary of what’s to be displayed, and doing the bitwise math to it. How that translates to writing the correct things to the pins. Can anyone explain what’s going on?

Waitaminute . . . .

is it shifting that 00000001 across the input binary to get a 1 when the 1's line up? like sliding across? Seems on the tip of my tongue or brain

Pin 9 checks 00000001 Pin 8 checks 00000010 Pin 7 checks 00000100

etc

as pins 2-9 are connected to segments A-DP?