Longer Bit Contants, Please

I write C on Arduino and while pointers are near and dear to me I only take them out for beginners who may be ready for them, same as bits and bit-logic. I look at what you wrote and it's like if you don't find it, something is wrong with Arduino... where's the logic in that? Keep digging or A-s-k.

If you want to make bit patterns with spaces between, you need to interpret the text yourself or use bigger code than you need from some library you don't understand to read text and output bytes.

If that is completely beyond you then maybe you've been leaning on black boxes a bit too much to write your own state machines.

This is what Arduino uses: AVR Libc Home Page

BTW, hex is a lot easier to write bit patterns with.

I'd say that you have solved the problem perfectly by defining your own variable mnemonics to use later in you program instead of explicitly using binary or hex representations. So you have to do it once only.

This is how it is done in various Microchip libraries:

/* AC - Analog Comparator */
/* AC.CTRLA  bit masks and bit positions */
#define AC_ENABLE_bm  0x01  /* Enable bit mask. */
#define AC_ENABLE_bp  0  /* Enable bit position. */
#define AC_HYSMODE_gm  0x06  /* Hysteresis Mode group mask. */
#define AC_HYSMODE_gp  1  /* Hysteresis Mode group position. */
#define AC_HYSMODE0_bm  (1<<1)  /* Hysteresis Mode bit 0 mask. */
#define AC_HYSMODE0_bp  1  /* Hysteresis Mode bit 0 position. */

btw, I'd use an unsigned integer (uint16_t) instead of int for your constants.

I appreciate the effort. Thank you.

Though, I don't want the hex version. I only want the binary version, because I generally assign by bit positions.

What you want requires a different compiler version as discussed. Either you wait until the Arduino environment moves to this or you just go with the flow and use comments or bitwise OR to set the bits in a readable way like it’s frequently done for registers

And hex makes that easier.

0 = 0000 4 = 0100 8 = 1000 C = 1100
1 = 0001 5 = 0101 9 = 1001 D = 1101
2 = 0010 6 = 0110 A = 1010 E = 1110
3 = 0011 7 = 0111 B = 1011 F = 1111

Don't expect to get this at a glance it's something to into long term memory.
Until then, how really hard is it to figure 4 bits from 0 to 15?

Other thing is to know in general the 7-bit ASCII table when working with text.

char A = 'A'; // you don't need to look the number up. just how ASCII is laid out

char n = '7'; // suppose we read this value from serial instead

if ( n - '0' == 7 ) { print( "oh wow, it is!" ); } // text math

Thank you for the reply, the base-16 number system and I have met before.

Unfortunately, converting the values will complicate my project by doubling my effort. I need to assigned bit positions for certain things.

Unfortunately also, the apostrophe nibble separator does not work with 1.8.15

I'm having a déjà vu:

As mentioned earlier, you have to enable C++14 for it to work.

Edit your platform configuration:

28c28
< compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto
---
> compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++14 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto

I’ve just noticed that under the section entitled “element definition” in the first picture, there are a number of errors in converting the hex representation to binary.

Yes, indeed! I did notice them; that is why I started this thread, asking for the nibble spaces. When I stated that it would help readability, I wasn't kidding.

Unfortunately, even following links, I do not see enough information to swap compilers, and I strongly suspect there is a reason why Arduino did not do so, as in compatibility problems.

I just want to write small compact efficient code, as best I can.

You don't have to swap compilers. You just tell the compiler to compile your code with the newer C++14 features by replacing the -std=gnu++11 flag by -std=gnu++14.

In which file?

BTW, the Arduino's editor is not on board with this whole apostrophy thing.
If it can work with int's this page needs updating: Arduino - IntegerConstants

You can learn about the Arduino boards platform system here:
https://arduino.github.io/arduino-cli/latest/platform-specification/

Although the information is not essential to make this small modification, it is useful for someone like yourself who desires the compiler to work differently than it does by default. You might even decide to make your own custom platform, which is not so difficult as it might sound due to the ability to reference resources from other platforms.

Arduino is very conservative about making changes like this to the boards platforms. For the target user, stability and portability is more important than having advanced shiny new language features.

Why not do something like this?

const uint16_t neuron_mfst_action = bit(12);
const uint16_t neuron_mfst_body = bit(13);
const uint16_t neuron_mfst_contextual = neuron_msft_action | neuron_msft_body;

This one:

On Linux, it's in ~/.arduino15/packages/arduino/hardware/avr/1.8.4/platform.txt, on Windows, probably in some (hidden?) AppData folder with a similar path.

The file is named platform.txt. You can find the location of it by doing this;

  1. Select File > Preferences from the Arduino IDE's menus.
  2. Check the box next to "Show verbose output during: compilation".
  3. Click the OK button.
  4. Select the board you are interested in from the Arduino IDE's Tools > Board menu. Note that this is a platform-specific modification, so it will affect only one set of boards. If you want it to apply to multiple boards then you'll need to modify each boards platform by repeating this process.
  5. Select Sketch > Verify/Compile from the Arduino IDE's menus. It doesn't matter what sketch you compile.
  6. Wait for the compilation to finish.

Now examine the contents of the black console pane at the bottom of the Arduino IDE window. There you will see something like this:

Using core 'arduino' from platform in folder: C:\Users\per\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

That is the location of the platform.txt file you need to modify.

Because it would be much slower for me, and more difficult to check because I may use an odd number of bits packed into one variable, such as these three bits do....

Without knowledge of you exact field of use it’s hard to offer alternative. Are you interfacing with a device (which one) and you need to represent some binary commands or flags?

I found the setting file in: C:\Program Files (x86)\Arduino\hardware\arduino\avr

Unfortunately, I suspect it can only understand them as enclosing delimiters.
I appears not to work.

crap:1:45: error: missing terminating ' character
const int neuron_mfst_action =0b0001'000000000000; // Outgoing Potentially Triggering Outgoing Messages
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
crap:2:1: error: expected ',' or ';' before 'const'
const int neuron_mfst_body =0b0010000000000000; // Message Parts of the System
^~~~~
exit status 1
missing terminating ' character

While that's of course a reasonable trade-off, what is the policy when it comes to C++ version upgrades? Surely we can't stay on C++11 forever, it's over 10 years old at this point, with C++14, C++17 and C++20 being released already, each of them adding features that can be really helpful for embedded programming, especially things like constexpr and consteval.
Even small improvements like being able to write 0b1111'0000 do add up. Class template argument deduction greatly simplifies user code and examples for libraries that rely on templates, some templates can be replaced by consteval functions or C++20 concepts, significantly improving error messages, and so on.

C++14 is a relatively small upgrade, and I wouldn't expect much problems. Teensy has been using C++14 for quite some time now, and ArduinoCore-mbed also uses C++14 (it uses the toolchain's default, perhaps by accident or because of Mbed requirements?).
Is this being looked into by the Arduino team? E.g. doing compilation tests for a selection of libraries and examples?

On a similar note, are there any plans to get rid of -fpermissive? I believe it is doing active harm, letting many mistakes through without errors, resulting in runtime crashes that would have been caught by the compiler otherwise.

That's the wrong file. See Pert's answer: