Editing Embedded Programming Tips and Tricks
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | =Fast Division= | + | ===Fast Division=== |
On microcontrollers without a divide instruction very fast division can be done by bit shifting a variable right.<br> | On microcontrollers without a divide instruction very fast division can be done by bit shifting a variable right.<br> | ||
Each shift does a divide by two.<br> | Each shift does a divide by two.<br> | ||
Line 8: | Line 8: | ||
''X = X >> 4; (Will result in a divide by 16)<br>'' | ''X = X >> 4; (Will result in a divide by 16)<br>'' | ||
− | By adding a multiplication you can achieve a limited number of | + | By adding a multiplication you can achieve a limited number of extra divisions.<br> |
For example<br> | For example<br> | ||
Line 18: | Line 18: | ||
Be sure to do the multiply first, otherwise bits will be lost.<br> | Be sure to do the multiply first, otherwise bits will be lost.<br> | ||
Also be sure the variable size is large enough to store the multiplied value.<br> | Also be sure the variable size is large enough to store the multiplied value.<br> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |