(Source: en.wikipedia.org)

Contents

^ Motorola M68000 Family, Programmer's Reference Manual (PDF). In this section, we'll learn how bits and bytes encode information.

The bit stores just a 0 or 1: it's the smallest building block of storage. ASCII is an encoding representing each typed character by a number Each number is stored in one byte (so the number is in 0.255) A is 65 B is 66 an is 96 space is 32 “Unicode” is an encoding for mandarin, Greek, Arabic, etc.

Each letter is stored in a byte, as below 100 typed letters takes up 100 bytes When you send, say, a text message, the numbers are sent Text is quite compact, using few bytes, compared to image etc. One byte works well for individual characters, but computers are also good at manipulating numbers.

Integers are typically stored with either 4 or 8 bytes 4 bytes can store numbers between -2147483648 and 2147483647 8 bytes can store numbers between -9223372036854775808 and 9223372036854775807 Adding in binary is just like normal addition with carrying But when you run out of bits you can't carry any more Leftmost bit indicates sign, so carrying to the leftmost bit changes a number from positive to negative. Related Hex Calculator | IP Subnet Calculator The binary system is a numerical system that functions virtually identically to the decimal number system that people are likely more familiar with.

Apart from these differences, operations such as addition, subtraction, multiplication, and division are all computed following the same rules as the decimal system. Almost all modern technology and computers use the binary system due to its ease of implementation in digital circuitry using logic gates.

(Source: www.slashgear.com)

It is much simpler to design hardware that only needs to detect two states, on and off (or true/false, present/absent, etc.). Using a decimal system would require hardware that can detect 10 states for the digits 0 through 9, and is more complicated.

Below are some typical conversions between binary and decimal values: DecimalBinary00112103114100711181000101010 16 100002010100While working with binary may initially seem confusing, understanding that each binary place value represents 2 n, just as each decimal place represents 10 n, should help clarify.

2 n 2 4 2 3 2 2 2 1 2 0 Instances within 1810010Target: 1818 – 16 = 22 – 2 = 0Converting from the binary to the decimal system is simpler. The only real difference between binary and decimal addition is that the value 2 in the binary system is the equivalent of 10 in the decimal system.

Note that the superscripted 1's represent digits that are carried over. A common mistake to watch out for when conducting binary addition is in the case where 1 + 1 = 0 also has a 1 carried over from the previous column to its right.

Note that the superscripts displayed are the changes that occur to each bit when borrowing. Binary multiplication is arguably simpler than its decimal counterpart.

(Source: blog.relationshipsurgery.com)

Note that in each subsequent row, placeholder 0's need to be added, and the value shifted to the left, just like in decimal multiplication. The complexity in binary multiplication arises from tedious binary addition dependent on how many bits are in each term.

Typically, the 0 placeholder is not visually present in decimal multiplication. While the same can be done in this example (with the 0 placeholder being assumed rather than explicit), it is included in this example because the 0 is relevant for any binary addition / subtraction calculator, like the one provided on this page.

Without the 0 being shown, it would be possible to make the mistake of excluding the 0 when adding the binary values displayed above. Note again that in the binary system, any 0 to the right of a 1 is relevant, while any 0 to the left of the last 1 in the value is not.

The dividend is still divided by the divisor in the same manner, with the only significant difference being the use of binary rather than decimal subtraction. Refer to the example below, as well as to the binary subtraction section for clarification.

99 trillion. If you meant the largest number, it's infinity. Of course if you add one to it, then that would be the largest number, which still equals infinity. So the reality is that there is no such thing as the largest number, it's a bit of a paradox.

(Source: www.anyandallauctions.com)

Recently in my day job, I came across some C code that just felt inefficient. I did a quick test on an Arduino, and was surprised to see that the first example compiled in to 512 bytes, and the second (using bit shift) was 516.

I ran across this code in a project targeting the Texas Instruments MSP430 processor. The MSP430 Launchpad is very Arduino-like, and previous developers had to do many tricks to get the most out of the limited RAM, flash and CPU cycles of these small devices.

I do not know if I can get in the habit of doing my integer splits this way, but perhaps I should retrain myself since this does appear incrementally better. Update: Timing tests (using mills() on Arduino, and clock() on PC) show that it is also faster.

This prevents the compiler from optimizing them out (since they are never used unless you uncomment the prints to display them). This entry was posted in Arduino, C Programming on December 16, 2014, by Allen Huffman.

In 1987, I wrote a small set of 7-digit decimal floating-point functions in 6502 assembly for a product at work. There will always be a place for floating-point, especially with calculators where the applicable ranges cannot be anticipated; but I have mostly quit using floating-point for data acquisition and control for everything up to and including the fast Fourier transform (FFT) for spectrum analysis.

(Source: www.fortinet.com)

With big look-up tables, we can get greater speed and get all 16 bits correct, with no interpolating, and no error from using less-than-perfect algorithms to calculate the functions with limited precision. In some cases, the look-up can be nearly a thousand times as fast as calculating the function, even much, much faster than CORDIC which is a successive-approximation method.

Suppose the 10 is a voltage on a power supply that will never exceed 14V, and you measured it with a 10- bit A/D converter that gives its 1023 maximum output at 15V × 1023 / 1024. Now dealing with bigger numbers, the accuracy and precision suddenly improve.

And by the way, real-world I/O in control situations is never floating-point, whether timers, counters, A/D and D/A converters, servos, etc. A chemist friend didn't think it would work because he frequently needs to use Avogadro's number (6.0221415×10 23).

This 43-range one below was pretty special to me in the late 1970s when I was making under $4/hour and Radio Shack had them for $49.95 CIRC (which would be somewhere near $200 in 2014 dollars) and then they brought them down under $30 on sale, and I grabbed one! The mirrored scale is used to eliminate parallax (although that's not to say the instrument's accuracy will match the precision).

Full scale each small mark10:1 interpolating.125V2.5mV250µV.25V5mV500µV1.25V25mV2.5mV2.5V50mV5mV5V100mV10mV10V200mV20mV25V.5V50mV50V1V100mV125V2.5V.25V250V5V.5V500V10V1V1000V20V2VIn spite of it being an analog meter, it has a range of about 4,000,000 to 1. NOW, the user sets the scale to make the best use of the range of readings the meter can give for the application.

(Source: collectiondx.com)

You may be wondering about base conversions for when you want decimal input and output even though the computer internally uses hexadecimal. After all, we're also talking about handling things like decimal points and signs for input and output.

It does require multiplication and division, but you only do it when it's time for human I/O, and otherwise let the computer do its business efficiently in hex. It should give the basic understanding, so you can write suitable routines.

In the Forth programming language, the decimal point automatically makes the result double-precision; but you can convert back to single if you want to. Divide your number by what's in variable BASE, and use the remainder to add a text digit to the build, even if it's a 0.

You can add a decimal point or other characters between digits, e.g. 12.345 or 12:36:40 (actually you might want to change BASE from 10 to 6 and back for the time readout, if you started with a number of seconds!) The way Forth does this output number formatting is somewhat explained starting at about the middle of the page of chapter 5 of Leo Brodie's “Starting Forth” (with ANS updates here, and they're mostly calling single-precision 32- bit, like I want for the 65Org32 with all 32- bit registers).

Subroutines or look-up tables could be made for virtually any function, scaling the inputs and outputs to take advantage of the resolution available in your standard cell size. You can download the files linked below, or I can supply 1Mx8 EPROM pairs with the tables pre-programmed into them.

(Source: blog.relationshipsurgery.com)

Many thanks to Tony (Nightmare tony on the 6502.org forum) for helping get them programmed on his Needham's Electronics EMP-10 programmer, and for donating some ST Microelectronics M27C801-100's for this. If you have questions or comments or find problems, please email me at the address at the bottom.

AboutHexFiles.html has a description of all the hex files, including differences between similarly named ones and how to change the bank number if desired. I might later provide more application code, but for now, any reader with some strength in math will be able to see what needs to be done to take advantage of the tables and meet his need, and the hard part (forming the tables themselves) is already done for him.

Since my own Needham's EPROM programmer software seems to have a bug in it for large files (and Needham's is out of business), I went on a quick search and found Record 1.60. Initially I just wanted to confirm that my Intel Hex files were valid and error-free as far as Intel Hex goes; but this software also lets you transform EPROM file types, concatenate, split, etc.

Version 1.52 is in the Ubuntu (Linux) software center for one-click download and installation. Record is command-line-only, which initially made it confusing because I didn't see any new icons and couldn't find it under “Applications”.

Much of the manual is spent on telling about multitudes of file types you will never use, so there's not really that much that you have to read. And as always, integers still allow you to handle the remainder from the division for minimizing or avoiding rounding errors in especially the smaller numbers.

(Source: www.pushsquare.com)

The automated test equipment (ATE) shown in my project pages on 6502.org did not use any floating point, even for logarithms (for dB). CalcMethods.html, for the curious, tells how I calculated the tables and formed the files using my HP-71 hand-held computer.

Here's a diagram to show the idea, since the shift-register interface method is less well known among hobbyists: It's msb-first in all cases, the 6522's SR, the 74HC165, and the 74HC595, so you don't have to reverse any bit orders, either in hardware or software.

The low-to-high transition transfers the '595 shift-register contents to the output latches, and the high level freezes the parallel input of the '165 and allows it to be shifted out. The three 74HC595's give 24 output bits, a little more than any EPROM needs for address lines.

You could use a couple of the '595 output bits to select which EPROM you're reading instead of adding more address-decode logic, but I don't particularly recommend it because if you accidentally enable both EPROM son power-up before the 595's are initialized, you'll have bus contention, along with possibly high currents and hot parts. Using the one additional address bit (for 21) and feeding the CS\ and OE\ of one of the EPROM's through an inverter to make sure they can't both be enabled at once would probably be best.