Least integer again.

Interested in Robotics? Here's the place to be.
Post Reply
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Least integer again.

Post by hlreed »

I have said before that you need two bits to make an integer. That is not quite true. An integer is a number whose most significant digit is a sign bit. With one bit, MSB and LSB are the same, so you have two values, 0 and -1.
You have to have two digits to make a positive integer.
Here is a theorom to prove. All integers have one more minus number than they have positive numbers.<p>A robot needs to know if a number is negative or positive. Which is why this post is here. A motor, given only a positive number will run away. Given an integer it will find the center.
Harold L. Reed
Microbes got brains
dyarker
Posts: 1920
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: Least integer again.

Post by dyarker »

Take the two bit number as the simplist case. A sign bit and a value bit. There are four states:<p>1 1 = -1
1 0 = -0
0 0 = +0
0 1 = +1<p>for an equal number of positives and negatives. On the other hand, in twos complement:<p>1 0 = -2
1 1 = -1
0 0 = 0
0 1 = +1<p>for there being one more negative in a fixed number of bits. It depends on what system you use.<p>One bit can be a positive integer, +1 and 0, with negatives impossible. Actually there are NO negatives in binary! Declaring that the MSB is a sign bit, is a work-around that makes computing with signed integers tolerable for CPU engineers and low level programmers (OS and compiler writers). In fact, check the registers of a CPU or microcontroller; you'll see that the accumulator has a separate sign bit in the flags register.<p>And signed integers aren't needed for (like robot) control either. With bytes we can say a value of 128 is no movement, larger is forward, smaller is reverse. With 128 there is one more reverse than forward value. Change no movement to 127 the situation is opposite. Two bits is minimum for Forward-stop-reverse. Which combination of bits represents stop, and what to do with the one "extra" value, is up to the programmer.<p>By "motor" I assume you mean "servo". Because a motor's output is proportional to input power, and inversely proportional to load. A motor can be the mussel(sp?) in a servo. A very simple servo is a motor and a person with a switch. The feedback is the person seeing, hearing, guessing, etc, that now is the time to stop, or more is needed, and changing the position of the switch.<p>An example of a mechanical automatic servo is the rotating balls on a steam engine. As engine load changes the RPM, inertia on the balls changes. Position of the balls controls a steam valve.<p>Inside an RC servo, circuitry contols the motor based on pulse width. This is a double loop servo system. The inner loop is the circuit telling the motor to move till position feedback matches the input. The outer loop is the person with a joystick seeing current position of model, and moving the joystick to acheive future position.<p>Robotics is the moving of some, or all, of the outer loop processing from a person to the machine. (Battlebots and Robotica are fun, but not robots. More like RC demolition derby. Summo bots and line followers are robots. Sensor feedback determines next move.)<p>Cheers
Dale Y
dyarker
Posts: 1920
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: Least integer again.

Post by dyarker »

Geez, all that and I forgot the "proof".<p>Given:
1. For any number of bits greater than zero, there is an even number of possible states.
2. In twos compliment binary arithmatic the MSB is defined as "zero" for positive and "one" for negative.
3. In twos compliment binary arithmatic all bits set to "zero" is defined as the value zero.<p>Proof:
One state (zero) from an even number of possible states, results in an odd number of states remaining. Zero uses one of the possible positive states, with MSB set to "0". Therefore, there must be one more negative value then there are non-zero positive values.<p>Total count (even) == Positives (odd) + Zero (odd) + Negatives (even).<p>------------------------
On the other hand, strickly speaking, you could say zero is a positive value because it's MSB is "0". Then there would be an equal number of positive and negative numbers. Hee, hee!
Dale Y
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: Least integer again.

Post by hlreed »

Ok, you got it.
if 0 is positive, then there are equal numbers of negative and positive.
Check
-2 1
-1 2
0 1
1 2<p>-2 to 0 to 1.<p>Of course 0 is both negative and positive which should cancel so it has no sign.
Note that we say -128 to 127 for 8 bits.
80h to 7Fh. Add 80h to that and it is 00h to FFh
It is a matter of phase and where you put the center. That is what you have to do to tell the robot it is center. Detecting 0 is easy. Detecting 128 requires a comparison (subtraction).<p>I don't see how a separate flag bit would work. How does the flag know the number is minus? Minus has to be carried on the number.
Harold L. Reed
Microbes got brains
dyarker
Posts: 1920
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: Least integer again.

Post by dyarker »

Normally we don't see the flags register unless doing assembly programming. The OS takes care of it.
Dale Y
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Re: Least integer again.

Post by bwts »

Ur always reinventing the digit H<p>B)
"Nothing is true, all is permitted" - Hassan i Sabbah
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: Least integer again.

Post by hlreed »

I want to make math into machines or make machines of math. Older I get the more Pythagorean I become.
Harold L. Reed
Microbes got brains
Post Reply

Who is online

Users browsing this forum: No registered users and 65 guests