Is "0xc0,0xf9,0xa4,...." represent the number in programming?

Hi all,

I come across somewhere this part of coding that will show the number display.

My question is as above, what is 0xc0,0xf9 in the table below?


int latch=11;
int clock=12;
int data=8;

unsigned char table=
{0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0xff};

void setup()
{
pinMode(latch,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(data,OUTPUT);
}
void Display(unsigned char num)
{

digitalWrite(latch,LOW);
shiftOut(data,clock,MSBFIRST,~table[num]);
digitalWrite(latch,HIGH);

}
void loop()
{
Display(1);
delay(500);
Display(2);
delay(500);
Display(3);
delay(500);
Display(4);
delay(500);
Display(5);
delay(500);
Display(6);
delay(500);
Display(7);
delay(500);
Display(8);
delay(500);
Display(9);
delay(500);
Display(10);
delay(500);
Display(11);
delay(500);
Display(12);
delay(500);
Display(13);
delay(500);
Display(14);
delay(500);
Display(15);
delay(500);
}[

It is a table of numbers written in hexadecimal representation aka format.
You can recognize these as the start with 0x

Where decimal rolls over at 9 -> 10, hexadecimal rolls over at fifteen.
The numbers above 9 are written as A B C D E F

give a look at - http://www.asciitable.com/ how hex and deci map onto each other

This hex format is often used as you can derive the bit pattern quite easily from it.

ps, please use code tags for posting code, you can update your post from the menu in the lower right.

robtillaart:
It is a table of numbers written in hexadecimal representation aka format.
You can recognize these as the start with 0x

Where decimal rolls over at 9 -> 10, hexadecimal rolls over at fifteen.
The numbers above 9 are written as A B C D E F

give a look at - http://www.asciitable.com/ how hex and deci map onto each other

This hex format is often used as you can derive the bit pattern quite easily from it.

Thank you for your explanation. Lets say if we put 0xf8 in the coding and what number will come out? to calculate the number?

edry:
Thank you for your explanation. Lets say if we put 0xf8 in the coding and what number will come out? to calculate the number?

Just Google it?

In decimal representation, 67 = 610+71.

It's the same for hexadecimal, just with base 16 instead of 10.
0xF8 = 1516+81

Try this

void setup()
{
  Serial.begin(115200);
  Serial.println(0xf8, HEX);
  Serial.println(0xf8, DEC);
  Serial.println(0xf8, BIN);
  Serial.println(0xf8, OCT);
}

void loop()
{
}

Each of the values printed is the same number but a different representation of that number in a different number base.

UKHeliBob:
Try this

void setup()

{
  Serial.begin(115200);
  Serial.println(0xf8, HEX);
  Serial.println(0xf8, DEC);
  Serial.println(0xf8, BIN);
  Serial.println(0xf8, OCT);
}

void loop()
{
}



Each of the values printed is the same number but a different representation of that number in a different number base.

Thank you.

PieterP:
Just Google it?

In decimal representation, 67 = 610+71.

It's the same for hexadecimal, just with base 16 instead of 10.
0xF8 = 1516+81

Actually this code is used with 8 segment display. Code run will show number from 1 to 9 and a b c d e on display.

Let say 0xF8 = 1516+81 will be 248 in decimal. What is connection 248 decimal with number show in display?

Sorry I am seriously beginner in programming.

edry:
Actually this code is used with 8 segment display. Code run will show number from 1 to 9 and a b c d e on display.

Let say 0xF8 = 1516+81 will be 248 in decimal. What is connection 248 decimal with number show in display?

Sorry I am seriously beginner in programming.

To drive a segment-display, the number is not looked as a whole but as each individual bits. For example: 0xF8 = 0b11111000, each bit will indicate on (1) or off (0) on each segment thus making a whole symbol in the display.

this code is used with 8 segment display.

NOW you tell us this.
The array most likely maps a small integer (0-15) to a bitmask of the segments used to display that integer on your 8segment display (one bit per segment.) Which bit numbers actually make up each digit are highly dependent on how things are wired. But I'm guessing that it's a common-anode display of some sort, so that 0xC0 means segment 0x80 and segment 0x40 are off, which would display an zero-like figure if 0x80 is the decimal point and 0x40 is the middle segment. Or something like that.

Go to the place you got it from and look at the circuit.

You have to invert the bits to figure out which led segments are on due to this statement:

shiftOut(data,clock,MSBFIRST,~table[num]);

The "~" operator inverts all the bits from the table you are using. Here's a similar table (from a different program) that uses the same logic, a zero bit means the led segment is on.

    0b11000000, // '0'  abcdef--
    0b11111001, // '1'  -bc-----
    0b10100100, // '2'  ab-de-g-
    0b10110000, // '3'  abcd--g-
    0b10011001, // '4'  -bc--fg-
    0b10010010, // '5'  a-cd-fg-
    0b10000010, // '6'  a-cdefg-
    0b11111000, // '7'  abc-----
    0b10000000, // '8'  abcdefg-
    0b10010000, // '9'  abcf-fg-

You've got a 7 segment display. So in order to display a number you need to decide which of the 7 segments to light up and which to leave dark. Now imagine that we had an 8-bit integer and we let each bit represent one segment, a to g. So a 0 might be 01111110. So the first bit isn't used, the second bit is a 1 if segment a should be lit and a 0 if it should be dark and the next bit is a 1 if the b segment should be lit and 0 if it shouldn't and so on and so forth. Now instead of writing those out in binary, we write them out in hexadecimal. And you get what you have.

edry:
Actually this code is used with 8 segment display. Code run will show number from 1 to 9 and a b c d e on display.

Let say 0xF8 = 1516+81 will be 248 in decimal. What is connection 248 decimal with number show in display?

Sorry I am seriously beginner in programming.

What you have in the code is a so-called lookup table

unsigned char table[]=
{0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x86,
0xff};

It’s an array of bytes. An array element is accessed using its index. The function Display takes a number as a parameter

void Display(unsigned char num)

that is used as the index in the table

  shiftOut(data,clock,MSBFIRST,~table[num]);

So if you pass 0 to the function, it will shift out the first element of the table array (0xC0); and if you pass 15, it takes the 16th element (0xFF).

The ~ in front of table[num] inverts the byte before shifting it out so a bit that is logic ‘1’ becomes logic ‘0’ and vice versa. Or maybe easier for a beginner, a bit that is HIGH becomes LOW and vice versa. So e.g. 0xFF in the table is shifted out as 0x00 and 0xC0 is shifted out as 0x3F.

Edry, firstly as a newbie - welcome. The explanation below will probably be criticised as being oversimplified but you say you are very new to programming so I will try and keep it simple

The numbers are hexadecimal (base 16) as opposed to decimal (base 10) which is what we humans normally use to count. Actually computers count in binary (base 2) because all they really do is turn bits (switches) on and off - ie switch them between 0 and 1- they just do it very bloody fast. A single bit rolls over (is reset to 0) every 2nd count:
0, 1, 0, 1, 0, 1...
Two bits roll over ever 4th count (2 to the power of 2)
00, 01, 10, 11, 00...
Three bits roll over ever 8 counts (2 to the power of 3), four bits every 16 counts (2 to the power of 4). You get the picture. Once you realise how computers work you can see that decimal numbers are not that useful for programming because they dont 'roll over' as a power of 2. However writing numbers out in binary is a pain in the bum because even small numbers become quite long. 42 in binary is 101010. So programmers learn to think in octal (base 8 ) or hexadecimal (base 16 - 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E).

Binary numbers are given the prefix 0b, octal numbers are given the prefix 0o and hexadecimal numbers are given the prefix 0x. So the decimal number 42 is:
0b101010
0o52
0x2A

If you want to get a deeper understanding try looking at this tutorial