-15
unsigned int PointSet[] = { (10<<16) | 3, (4<<16) | 2, 0xFFFF0002 };

What does this mean ?

| 3 what operation is it?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
sokol guri
  • 23
  • 3
  • 2
    `|` is bitwise OR. `| 3` will set the last two bits to ones. – Cornstalks May 14 '17 at 16:38
  • It is a *bitwise OR* – David C. Rankin May 14 '17 at 16:38
  • This array is initialized with constants computed at compile time using bitwise operators. `|` is bitwise `OR`, `<<` is bit shift, `0x` is a prefix for hexadecimal integer literals. – Sergey Kalinichenko May 14 '17 at 16:39
  • Read https://www.tutorialspoint.com/cprogramming/c_bitwise_operators.htm – Ajay May 14 '17 at 16:39
  • 1
    Possible duplicate of [What does the vertical pipe ( | ) mean in C++?](http://stackoverflow.com/questions/10164086/what-does-the-vertical-pipe-mean-in-c) – phuclv May 14 '17 at 16:44
  • 2
    Stack Overflow is not a replacement to reading a book. There are many online resources available on the safe. You can post problems here which you are having a hard time solving. Read a book on C. – Ajay Brahmakshatriya May 14 '17 at 16:52
  • Next time you see some unfamiliar symbol in C code, please consult a C book. Even a simple search for "C operators" would have given the information. We are not a tutoring service! Being a programmer means thinking for oneself, not expecting to be spoon-fed for every simple thing. – too honest for this site May 14 '17 at 17:15

2 Answers2

2

This creates an array of three integers. The commas separate the constant-value expressions. The | is bitwise OR operator.

(10<<16)|3 = (0xA<<16)|3 = (0x000A0000)|0x3 = 0x000A0003
(4<<16)|2 = (0x00040000)|0x2 = 0x00040002

Your array is { 0x000A0003, 0x00040002, 0xFFFF0002 }

Wheezil
  • 3,157
  • 1
  • 23
  • 36
0
unsigned int PointSet[] = { (10<<16) | 3, (4<<16) | 2, 0xFFFF0002 };
         10 = 0000 0000 0000 0000 0000 0000 0000 1010 (Binary)
0x0000000A =    0    0    0    0    0    0    0    A
              0000 0000 0000 1010 0000 0000 0000 0000 (16 bit shift)
0x000A0000 =    0    0    0    A    0    0    0    0
         3 =  0000 0000 0000 0000 0000 0000 0000 0011
0x000A0003 =  0000 0000 0000 1010 0000 0000 0000 0011 (... | 3)

0x00000004 =  0000 0000 0000 0000 0000 0000 0000 0100
0x00040000 =  0000 0000 0000 0100 0000 0000 0000 0000 (16 bit shift)
0x00000002 =  0000 0000 0000 0000 0000 0000 0000 0010 
0x00040002 =  0000 0000 0000 0100 0000 0000 0000 0010 (... | 2)

unsigned int PointSet[] = {0x000A0003, 0x00040002,0xFFFF0002};
Mahonri Moriancumer
  • 5,993
  • 2
  • 18
  • 28