Assembler, and therefore this course, too, very often use binary or hexa-decimal numbers. This page provides the basics of these number formats for beginners.

Binaries | Hexa-decimals | Conversion tools |
---|

Not only pure numbers are encoded in this mode, but also bits in registers, I/O ports or port registers. Those can only be one or zero. There is only one exception: Analog-Digital-converter input pins can handle non-digital voltages, but only to convert those to digitals.

All (theoretical and practical) number systems are based on a certain base number. The basis of our usual number system, the decimal system, is ten. We have ten digits, zero to nine, to construct all kind of numbers with those decimal digits.

In binary, based on two, only two digits are available: zero and one. If numbers reach or exceed the base number (ten or two), further digits are added to the left. Twelve in decimal is a one (left shifted a ten) plus a two. 12 in binary is a two (1 left shifted, a two) plus a one. So 12 in binary is 3 in decimal.

Numbers of any size can be handled like this. A five-digit decimal is

The last expression part, 10

The equivalen of decimal 12345 in binary is the following number:

This is even simpler that the decimal calculation, as all multipliers are either 0 (do not add the power term) or 1 (add the power term). By leaving the not-to-be-added terms away and by listing only those that are (trivially) added, this simplifies to

The decimal values of the powers of two are 1, 2, 4, 8, 16, 32, 64, 128, etc., and those we have to add to yield 12345 decimal.

It is clear, that larger decimal numbers, here: 5 digits, have more binary digits (here: 14).

But: no one has to handle now 40 digit (the largest in this course) long binaries and read through a half-line long number, as there are methods to simplify those numbers (see the hexa-decimal section below) and because there are tools available for this.

The every-day length in AVR processing is eight bits long, more does not fit into one register of the AVRs. Therefore the powers of 2 until decimal 128 have to be remembered, more is not needed (as long as you do not have to assemble for a 64-bit-CPU).

In the contrary: the small binaries are often the more powerful: one single bit allows to switch a LED on or off, three bits (CS02, CS01 and CS00) select whether the timer/counter 0 is prescaled by one or by 8, 64, 256 or even 1,024. Eight bits can drive a whole organ of LEDs. Small, but never-the-less powerful.

To signal to the assembler that the following number is meant as a binary number (not a decimal by default), we precede binaries by

In order to have bit 7 of a register set to one, the rest of it all zeroes, we formulate:

The

And, to make it even more in-transparent, we could define the decimal 12345 from above not as

and by kicking at the brain of the reader. Those who search for "12345" in the source code editor now, won't find it, it is carefully hidden now behind left shifters.

Binaries | Hexa-decimals | Tools |
---|

Decimal 12345 translates to hexa-decimal 0x3039, because

We see that this is the same logic like converting binaries, but with the larger base number 16 instead of 2. Simple, but effective.

Binaries | Hexa-decimals | Tools |
---|

The first: calculators are available for any operating system. You'll have to bring them to the programmer mode. The one you see here is from Windows 10. This one knows 64 bits resolution, others are shorter.

If you'll need more numbers to be converted: the LibreOffice spreadsheet has the functions DEC2BIN, BINTODEC,DECTOHEX and HEXTODEC. In later versions of LibreOffice even with 64 bit resolution.

©2018-2019 by www.avr-asm-tutorial.net/www.gsc-elektronic.net

Binaries | Hexa-decimals | Tools |
---|