Dividing by zero — the fundamental no-can-do of arithmetic. It is somewhat surrounded by mystery, and is a constant source for internet humor, whether it involves exploding microcontrollers, the collapse of the universe, or crashing your own world by having Siri tell you that you have no friends.
It’s also one of the few things
gcc will warn you about by default, which caused a rather vivid discussion with interesting insights when I recently wrote about compiler warnings. And if you’re running a modern operating system, it might even send you a signal that something’s gone wrong and let you handle it in your code. Dividing by zero is more than theoretical, and serves as a great introduction to signals, so let’s have a closer look at it.
Chances are, the first time you heard about division itself back in elementary school, it was taught that dividing by zero is strictly forbidden — and obviously you didn’t want your teacher call the cops on you, so you obeyed and refrained from it. But as with many other things in life, the older you get, the less restrictive they become, and dividing by zero eventually turned from forbidden into simply being impossible and yielding an undefined result.
And indeed, if a = b/0, it would mean in reverse that a×0 = b. If b itself was zero, the equation would be true for every single number there is, making it impossible to define a concrete value for a. And if b was any other value, no single value multiplied by zero could result in anything non-zero. Once we move into the realms of calculus, we will learn that infinity appears to be the answer, but that’s in the end just replacing one abstract, mind-boggling concept with another one. And it won’t answer one question: how does all this play out in a processor? Continue reading “Creating Black Holes: Division By Zero In Practice”
If there’s one thing C is known and (in)famous for, it’s the ease of shooting yourself in the foot with it. And there’s indeed no denying that the freedom C offers comes with the price of making it our own responsibility to tame and keep the language under control. On the bright side, since the language’s flaws are so well known, we have a wide selection of tools available that help us to eliminate the most common problems and blunders that could come back to bite us further down the road. The catch is, we have to really want it ourselves, and actively listen to what the tools have to say.
We often look at this from a security point of view and focus on exploitable vulnerabilities, which you may not see as valid threat or something you need to worry about in your project. And you are probably right with that, not every flaw in your code will lead to attackers taking over your network or burning down your house, the far more likely consequences are a lot more mundane and boring. But that doesn’t mean you shouldn’t care about them.
Buggy, unreliable software is the number one cause for violence against computers, and whether you like it or not, people will judge you by your code quality. Just because Linus Torvalds wants to get off Santa’s naughty list, doesn’t mean the technical field will suddenly become less critical or loses its hostility, and in a time where it’s never been easier to share your work with the world, reliable, high quality code will prevail and make you stand out from the masses.
Continue reading “Warnings Are Your Friend – A Code Quality Primer”
Telling time by using the current position of the sun is nothing revolutionary — though it probably was quite the “life hack” back in ancient times, we can assume. On the other hand, showing time by using the current position of the sun is what inspired [Rich Nelson] to create the Day Cycle Clock, a color changing light box of the Philadelphia skyline, simulating a full day and night cycle in real time — servo-controlled sun and moon included.
At its core, the clock uses an Arduino with a real-time clock module, and the TimeLord library to determine the sunrise and sunset times, as well as the current moon phase, based on a given location. The sun and moon are displayed on a 1.44″ LCD which doubles as actual digital clock in case you need a more accurate time telling after all. [Rich] generally went out of his way with planning and attention to detail in this project, as you can see in the linked video, resulting in an impressively clean build surely worthy as gift to his brother. And if you want to build one for yourself, both the Arduino source code and all the mechanical parts are available on GitHub.
An interesting next iteration could be adding internet connectivity to get the current weather situation mixed into the light behavior — not that it would be the first time we’d see weather represented by light. And of course, simulating the northern lights is also always an option.
Continue reading “Decorative Light Box Lets You Guess The Time”
Java isn’t everyone’s cup of tea. With all its boilerplate and overhead, you’re almost always better off with a proper IDE that handles everything under the hood for you. However, if you learn a new language, you don’t really want to be bothered setting up a clunky and complex IDE. If only you could use a simple, standard Windows program that you are most likely already familiar with. This wish led [RubbaBoy] to create the MSPaintIDE, a Java development environment that let’s you write your code in — yes — MS Paint.
If you’re thinking now that you will end up writing your program with MS Paint’s text tool and create a regular image file from it — then you are right. Once set up, MSPaintIDE will compile all your PNG source files into a regular Java JAR file. And yes, it has syntax highlighting and a dark theme. [RubbaBoy] uses a custom-made OCR to transform the image content into text files and wraps it all into few-button-click environment — including git integration. You can see a demonstration of it in the video after the break, and find the source code on GitHub.
One has to truly admire how far [RubbaBoy] went, considering the tongue-in-cheek nature of this project. And all joking aside, if you’re interested in OCR, this might just be simple enough to begin with. Or you could expand it with some text to speech functionality.
Continue reading “A Whole Other Kind Of Graphical Programming”
In case you happen to have an ocean nearby, you’re probably familiar with its rising and falling tides. And if mudflat hiking is a thing in your area, you’re also aware of the importance of good timing and knowing when the water will be on its way back. Tide clocks will help you to be prepared, and they are a fun alternative to your usual clock projects. If you’re looking for a starting point, [rabbitcreek] put together an Arduino-based tide clock kit for educational purposes.
If you feel like you’re experiencing some déjà vu here, this indeed isn’t [rabbitcreek]’s first tide clock project. But unlike his prior stationary clock, he has now created a small and portable, coin-cell version to take with you out on the sea. And what shape would better fit than a 3D printed moon — unfortunately the current design doesn’t offer much waterproofing.
For the underlying tide calculation itself, [rabbitcreek] uses just like in his previous project [Luke Miller]’s location-based library for the ubiquitous DS1307 and DS3213 real-time clocks. Of course, if you also want to keep track of other events on your clock, why not set up calendar events for the next rising tide?
In case you’re looking for a variety of IRC client implementations, or always wondered how botnets and other malware looks on the inside, [maestron] has just the right thing for you. After years of searching and gathering the source code of hundreds of real-world botnets, he’s now published them on GitHub.
With C++ being the dominant language in the collection, you will also find sources in C, PHP, BASIC, Pascal, the occasional assembler, and even Java. And if you want to consider the psychological aspect of it, who knows, seeing their malicious creations in their rawest form might even give you a glimpse into the mind of their authors.
These sources are of course for educational purposes only, and it should go without saying that you probably wouldn’t want to experiment with them outside a controlled environment. But in case you do take a closer look at them and are someone who generally likes to get things in order, [maestron] is actually looking for ideas how to properly sort and organize the collection. And if you’re more into old school viruses, and want to see them run in a safe environment, there’s always the malware museum.
Programming languages tend to polarize, and Rust is by far no exception. Whether it will stick around and grow as an alternative for the lower levels or not — time will tell. In the meantime, if you’re curious about the language and its low-level abilities yourself, [phil-opp] has written a series of blog posts on building your own little bare metal kernel in Rust.
Starting from the basics, [phil-opp] describes in detail the set-up and build process to create a standalone executable that won’t be linked against the Rust standard library. From here he proceeds to build a simple operating system kernel that prints a good old Hello World via VGA output — QEMU emulation included. And of course, there is a GitHub repository with all of the source code.
[phil-opp] has been working on this for a while already, and he is currently writing the second edition of the series. Some content is therefore still missing, but you may find more of it in his first edition. And in case you know absolutely nothing about Rust in the first place, let’s just take a step back and start with the basics. After all, we might see more of it in the future.