Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Inches and feet.

Status
Not open for further replies.
The quickest way on a micro is a loop taking 12 from inches and counting feet.

feet = 0
loop
inches -= 12​
feet++​
while inches > 12​

You'll be left with feet and inches.. Divide is slow on a micro..
 
Really hard to keep track of English units of length.
Thou or mill, line, inch, foot, yard, furlong, mile, league.
 
In spite of its strange, illogical relationship between units, we still cling to the English system in the US.
There was a national attempt to get people to convert to metric a number of years ago (some of the gas station pumps even converted to liters), but it didn't stick.
So we have the fun of needing two sets of wrenches and trying to determine whether the bolt we need to replace is metric or English, with the hardware store having to stock both types. :eek:
 
The inch and the foot are body part measurements. I'm constantly remided what 1', 2' and 4' are: floor and ceiling tiles.

I know what a mile is by walking and having it measured. By estimate is from my house to xyz.

I hate the unit pascals for pressure. It's too big.

Then I ordered 3m IEEE-488 cables instead of 3 foot long ones..

I don;t mind 0.001 inches. Then there is numbered, lettered and fractional drills.
 
You get short-changed on your 'gallon', for example.
Yes, I have no idea why there are two different sizes for that.

Also have the sort ton and the long (Imperial) ton.
Interesting the the long ton is within about 1.6% of the metric ton (tonne).
 
Last edited:
The quickest way on a micro is a loop taking 12 from inches and counting feet.

feet = 0
loop
inches -= 12​
feet++​
while inches > 12​

You'll be left with feet and inches.. Divide is slow on a micro..
Thank you so much. I won’t get used to it. I write this in my blog SPAM REMOVED
 
Last edited by a moderator:
Looking at the code again, it should actually be a loop with the test at the start [eg. while() - do] otherwise an input less than 12 inches will give an erroneous result.
 
First divide by four (right shift by 2 bits);

Then use the concept that 1/4 + 1/16 + 1/64 + 1/256 + ... = 1/3
(Note that each are two (additional) shifts to right. Put the shifts in a loop until a two-bit shift results in no change (zero).
Also, add 1 to the value to be divided by 3 before dividing to cover a rounding error.

Much faster if you have large inch values to convert.

Search StackOverflow for divide by 3 for details. Very compact code can be written to handle very large inch values in a few steps.
 
Then use the concept that 1/4 + 1/16 + 1/64 + 1/256 + ... = 1/3
Interesting gophert, I did not know that.
Or if I did, I had forgotten it long ago.

JimB
 
Ahh, Division by way of Multiplying..

Instead of dividing by four at the beginning you could simply remove the addition of 1/4...

1/16 + 1/64 + 1/256 + ... = 1/12

.... but how do you determine the "magic" series of numbers to add?

In this example we wanted to divide by 12

1) Find the reciprocal of 12 which is 0.08333333333333 ... 1/12 = 0.08333333333333
2) Determine the bit resolution multiplier ... for this example 8 bits of resolution = 256 ... 8^2 = 256
3) Multiply Step 1 by Step 2 and you get 21.33333333333
4) Round step 3 and convert it to Binary. The result is ... 00010101
5) On the left most side(MSB), the binary fractional weight starts at 1/2 and ends at 1/256 on the right most side(LSB). Where there is a "1" in the binary sequence you simply add that to the previous result.
MSB - 1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128, 1/256 - LSB
6) So it becomes ....
1/16 + 1/64 + 1/256 + ... = 1/12
 
Instead of dividing by four at the beginning you could simply remove the addition of 1/4...

Agreed but it was already an abstraction so I wanted to keep the "divide by 4 and divide by 3 concept" true.
 
1 furlong / fortnight = 0.000166309524 meters / second (LOL)

I can not remember; there is a measurement of land where a farm family can survive on. (old English) Only problem is this depends on water, weather, soil type and how hard you whip the farmer. Many farmers starved.
 
Now that we (the UK) are leaving :facepalm: the European Union, there are those would would have us abandon the SI unit system and return to the old illogical Imperial Units, inches, feet, yards, ounces, pounds, stones etc.
:facepalm::facepalm::facepalm::facepalm:

JimB
 
Now that we (the UK) are leaving :facepalm: the European Union, there are those would would have us abandon the SI unit system and return to the old illogical Imperial Units, inches, feet, yards, ounces, pounds, stones etc.
:facepalm::facepalm::facepalm::facepalm:

JimB

Illogical? Owing back to non-si units. Last time I was in the U.K., those traffic signs with a number in a red circle were calibrated in miles per hour instead of kmh like real metric countries.

What is the official definition of a mile in the U.K.? Are other non-metric units used (8-furlongs, 5,280 feet or 1,760 yards - and how are those defined?). In the US, an inch is officially defined as 2.54mm EXACTLY and all units flow from there.
 
Last time I was in the U.K., those traffic signs with a number in a red circle were calibrated in miles per hour instead of kmh like real metric countries.
Correct.
To this day, roadsign distances are in miles and speed limits are in miles per hour.
We never did get around to changing those things.
Similarly if we go to the pub, we may have a pint of beer. Litres, what are they?

But when I go shopping for groceries, weights are in (kilo)grams, and volumes are in (milli)litres.

In the world of engineering, all measurements are in SI units with a few odd exceptions.
Material sizes, wood, metal etc are often specified in Imperial sizes.
The sizes of wood blows my mind, it never seems to be the size stated, whatever units are used.

The oil industry can be a bit odd.
The drilling people mostly seem to work in Imperial units, feet, pounds, pounds per square inch, but the topside process people work in SI units.

JimB
 
No, I was serious. Is there a unit of imperial length that has an official metric length conversion definition in the U.K., as the US does?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top