Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I trying to port over the following code:


byte DIV_3_OF_5[8] = {
  B11100, 
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100
}; // 3 / 5

byte DIV_4_OF_5[8] = {
  B11110, 
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110
}; // 4 / 5


What is the C syntax for this, and how to define 0s and 1s in this case? Do I need to convert the number to hex?

What I have tried:

I have tried to migrate it over without success.
Posted
Updated 2-Feb-18 3:15am
Comments
Rick York 2-Feb-18 20:16pm    
Since that the values are all the same it should be easy to use the hexadecimal value 0x1E instead of the binary values.

1 solution

Some compilers support binary literals with a 0b or 0B prefix. They are not part of the C standard but has been introduced with C++14.

If you use such a compiler (e.g. GCC: Using the GNU Compiler Collection (GCC): Binary constants[^] ) it is sufficient to insert a zero. If not, you have to convert the values to hex.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900