Programming Languages
The programming ideas engineers use most: choosing a language, Python and C essentials, numbers and floating point, bits and data formats, numerical methods, filters and PID, data and files, and software practice.
Engineers write code to read instruments, control machines, process data, run calculations and glue tools together. You do not need to be a software specialist, but a handful of ideas (how numbers are stored, how to work with bits, how to write small testable functions, how to check a numerical answer) prevent most of the expensive mistakes. This guide gathers those ideas in nine pages with short, tested examples in Python and C: choosing a language, the essentials of Python and of C, numbers and floating-point, bits and data formats, numerical methods, filters and control code, data and files, and software practice. The examples are small enough to read in a minute and every worked number is computed, so you can check your own code against them.
Start here: what do you need?
| I need to… | Go to |
|---|---|
| pick a language for a project or a platform | Choosing a Language |
| analyze data, plot it, or talk to an instrument | Python for Engineers |
| write firmware or fast code, or read C written by others | C and C++ Essentials |
| understand why 0.1 + 0.2 is not 0.3, or why a total drifts | Numbers and Floating Point |
| work with hex, masks, byte order or a binary file format | Bits, Bytes and Data Formats |
| solve an equation, integrate a log, fit a curve or simulate a system | Numerical Methods |
| smooth a noisy reading, write a PID loop or find a frequency | Filters, PID and Signal Code |
| read CSV, JSON or serial messages, or handle time stamps and units | Data, Files and Parsing |
| organize a project, test it, find a bug or make it faster | Software Practice, Testing and Debugging |
A suggested order
If you are new to programming, start with Choosing a Language and the page for your first language, then read Numbers and Floating Point and Bits, Bytes and Data Formats: they explain most “impossible” results. The remaining pages are tools you reach for as the job needs them.
- Choosing a Language: Python, C, C++, MATLAB, Rust, JavaScript, SQL, shell and PLC languages compared, with how to pick one and set up the tools.
- Python for Engineers: The Python an engineer needs: data types, functions, NumPy and Matplotlib, instruments over serial, units, speed and virtual environments.
- C and C++ Essentials: Types and sizes, pointers and arrays, structures, the preprocessor, bit operations, undefined behavior and safe habits.
- Numbers and Floating Point: Integers and overflow, IEEE 754 floats, rounding error, cancellation, summing, comparing, units and significant figures.
- Bits, Bytes and Data Formats: Binary and hex, bit masks, two’s complement, byte order, packing fields, text encodings and reading binary data.
- Numerical Methods: Solving equations, integrating, differential equations, interpolation and curve fitting, with the error of each method.
- Filters, PID and Signal Code: Moving average and exponential filters, discrete PID with anti-windup, sampling, the Fourier transform and tuning by simulation.
- Data, Files and Parsing: CSV, JSON and binary files, parsing serial messages, time stamps, units, pandas, SQL and keeping raw data.
- Software Practice, Testing and Debugging: Version control, tests, reading and writing code others can use, how work grows with data, profiling, common bugs and a review checklist.
Why engineers write code
- Measure: read instruments, sensors and loggers and store the data (Data, Files and Parsing).
- Calculate: do the sums that a spreadsheet makes awkward: iterate, fit, simulate (Numerical Methods).
- Control: run a loop at a fixed rate that reads, decides and acts (Filters, PID and Signal Code, and Embedded Systems).
- Automate: repeat a test, a report or a conversion without a person (Python for Engineers).
- Explain: a script that reproduces a result documents how it was made.
The traps that cause most problems
| Trap | What happens | Where it is explained |
|---|---|---|
| Float equality | 0.1 + 0.2 == 0.3 is false | Numbers and Floating Point |
| Integer overflow and division | A counter wraps; 7 / 2 is 3 | Numbers and Floating Point and C and C++ Essentials |
| Byte order | A sensor reading looks plausible but is wrong | Bits, Bytes and Data Formats |
| Units | A result is out by a constant factor | Numbers and Floating Point and Data, Files and Parsing |
| Unequal time steps | A filter or PID behaves differently from the plan | Filters, PID and Signal Code |
| Off-by-one | A loop runs one time too many | Software Practice, Testing and Debugging |
| Tests skipped | A change breaks something nobody notices | Software Practice, Testing and Debugging |
Quick reference
| Topic | Rule or formula | Page |
|---|---|---|
| Float precision | float ≈ 7 digits (ε = 1.19 × 10−7); double ≈ 16 digits (ε = 2.22 × 10−16) | Numbers and Floating Point |
| Integer ranges | n bits unsigned 0 to 2n − 1; signed −2n−1 to 2n−1 − 1 | Bits, Bytes and Data Formats |
| Set / clear / toggle a bit | r |= 1<<n; r &= ~(1<<n); r ^= 1<<n | Bits, Bytes and Data Formats |
| Newton step | x ← x − f(x) ÷ f′(x) | Numerical Methods |
| Trapezoid rule | h [ ½ f0 + f1 + … + ½ fn ] | Numerical Methods |
| Exponential filter | y += α (x − y), α = Δt ÷ (τ + Δt) | Filters, PID and Signal Code |
| Discrete PID | u = Kp e + Ki ∫e dt + Kd de/dt | Filters, PID and Signal Code |
| Nyquist | sample at more than twice the highest frequency | Filters, PID and Signal Code |
Related guides and tools
- Embedded Systems: the C side of microcontrollers, interrupts, memory and RTOS.
- Bitwise and Register Field Calculator: masks, shifts and register fields.
- Data Logging, Robotics Tools and Machine Learning: where this code goes next.
- PLC and Logic Control: the IEC 61131-3 languages for machines.
- Industrial Communication: the data formats and protocols your code may need to speak.
Safety
- Code that moves things can hurt. A program that controls a motor, heater or valve needs hardware limits and an independent stop that does not depend on the software, and tests before it meets the real machine.
- Never trust input, from a sensor, a file or a network: check ranges and handle missing or garbled data.
- Safety-related control code (machine guarding, medical, vehicles) follows standards and needs certified tools and review; a script is not a safety system (see System Integration).
- Secrets and credentials do not belong in source code that you share.
FAQ
Which language should I learn first?
Python for analysis, automation and quick tools; C if your goal is microcontrollers and firmware. The ideas (variables, loops, functions, numbers, bits) are the same, so the second language is much easier than the first. See Choosing a Language.
Do I need to know object-oriented programming?
Not to start. Functions and a few data structures carry most engineering scripts. Classes help in larger programs and are standard in libraries you will use.
Why does my calculation give a slightly wrong answer?
Almost always because floating-point numbers are approximations, or because of a unit, a rounding or an integer-division mistake. Numbers and Floating Point explains how to tell which.
Where did the old Programming Languages sections go?
All of them are in this guide, with much more depth: numbers, bits, numerical methods, filters and the workflow each have their own page.
References
- Kernighan, B. W. and Ritchie, D. M., The C Programming Language; Matthes, E., Python Crash Course; the Python and NumPy documentation.
- IEEE 754-2019, Standard for Floating-Point Arithmetic; Goldberg, D., “What every computer scientist should know about floating-point arithmetic”, 1991.
- Press, W. H. et al., Numerical Recipes; Burden, R. L. and Faires, J. D., Numerical Analysis.
- Hunt, A. and Thomas, D., The Pragmatic Programmer.
Last reviewed: October 2026. Library versions and tool names change: check the current documentation for the language you use.
