There are 10 kinds of people in the world
If, like many embedded software developers, you need to work “close to the hardware”, you will want to be able to visualize the bit patterns that map on to CPU and peripheral registers. The obvious way to do this is in binary, as you can see the 1s and 0s directly. However, I do not think that I have ever seen the option, even in assembly language, to include binary constants in software. Do feel free to comment or email me if you know of examples.
When I started out with real-time programming, after I got through my Fortran phase, I worked on DEC minicomputers. As these machines originally had word sizes like 12 and 18 bits, grouping the bits into 3s and expressing values in octal was normal. A PDP-8, for example, was a “real” computer – i.e. it had a line of lights and switches on the front; the switches were grouped into 3s for mapping onto octal values. I was always comfortable with octal and could “see” the bit patterns quite intuitively.
Later on, a PDP-11 had 16 bit words, but DEC still insisted on using octal, which was rather odd – the left-most digit could only be 0 or 1. But the instruction set had 3-bit fields, which made some sense. In due course, with VAX machines, which had a 32-bit architecture, DEC gave in and started using hexadecimal like everyone else.
But I have never really quite felt at home with hex. Seeing “0x0C” does not immediately translate to “00001100” in my mind. So, for C/C++ code I wanted to fix this problem. All I need is my “binary.h” file, which contains 256 lines like this:
#define b00000000 ((unsigned char) 0x00)
#define b00000001 ((unsigned char) 0x01)
#define b00000010 ((unsigned char) 0x02)
This seems to do the job. If you would find this useful and would like a copy of the binary.h file, please email me.
It’s an old and rather geeky joke, but I like it:
There are 10 kinds of people in the world: those who understand binary and those who do not.
While I am on the subject of programming, you might be interested to attend a Webinar we are running on Thursday, which looks at compilers and embedded coding generally. A recording will be available after the live event.
Posted June 8th, 2009, by Colin Walls
- Choose your weapons – options for debugging
- Dissatisfaction, customer service and surprises
- Video blog about getting into embedded software
- Embedded software article: RTOS Revealed #9
- Lost in translation
- One return from a function: a good idea?
- The A380 experience
- Embedded Software Masterclass
- How to get rich