9bit arithmetics in C

G

Guest

Tim Harig wrote:
) On 2009-05-06, Willem <[email protected]> wrote:
)> Nonsense.  You don't need any standards for binary representation, all you
)> need is a way to map the emulated binary representation on an unsigned int.
)> Which is perfectly possible in standard C.
)
) All of the above values can be used to specify the number -127; but, they
) are not equivalant.

They are irrelevant.  All you use is the value itself: -127.

) If these binary values are used to control motors
) in a CNC mill they may not produce the same shape.

The emulator is not linked to a real CNC machine, is it ?
So, the CNC machine emulator should also be written in
standard C, using the value, and not caring about
the underlying representation.

I'd have thought even if it *were* connected to a CNC machine
you could do a conversion from internal to external format
before the CNC machine saw the bits. And I'd also have thought
the conversion could be done in portable C.
 
W

Willem

Tim Harig wrote:
)> -20 in 16bit twos compliment big endian is 1111111111101100 whereas it
)> is 1000000000001010 stored in 16 bit 1s compliment big endian. A big
)
) err, 1111111111101100 vs 1000000000001100

1 - You're thinking of sign-magnitude.
2 - Your first example would be -10 and your second would be -12.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
W

Willem

Tim Harig wrote:
) I am assuming that the original poster, in modeling the his hardware
) design, will at some point or another want to represent the binary
) structure, not just the arithmatic values, of the data inside of the the
) hardware that he is trying to simulate. This would be necessary, for
) instance, to know what the I/O pins on a microcontroller would be when
) outputing the result of a given calculation. The original poster may not
) need this.

Yes. You do that by casting to unsigned, shifting and anding. No need to
know the emulating machines underlying representations.

All the above operations are perfectly well-defined within C, without
regard to underlying representation.

Cast to unsigned is done modulo some large power of 2, shifting is
multiplying or dividing by a power of 2, and anding is also defined in
values with powers of 2.

) If this is the case, then it would be necessary to take into account how
) the hypothetical processor represents values internally. The poster said
) that he is simulating signed arithmetic; therefore, to know the physical
) representation the compliment used to store negative numbers is important.
) -20 in 16bit twos compliment big endian is 1111111111101100 whereas it
) is 1000000000001010 stored in 16 bit 1s compliment big endian. A big
) difference; especially, when trying to flatten the value to only 9 bits.

Yes, but you *don't* need to know how the emulating machine stores
anything. That's the whole point.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
J

JosephKK

Tim Harig wrote:
)> Nonsense. You don't need any standards for binary representation, all you
)> need is a way to map the emulated binary representation on an unsigned int.
)> Which is perfectly possible in standard C.
)
) All of the above values can be used to specify the number -127; but, they
) are not equivalant.

They are irrelevant. All you use is the value itself: -127.

) If these binary values are used to control motors
) in a CNC mill they may not produce the same shape.

The emulator is not linked to a real CNC machine, is it ?
So, the CNC machine emulator should also be written in
standard C, using the value, and not caring about
the underlying representation.

) To effectively model
) this system, it is necessary to that the the emulator deal with the same
) binary format as will the real hardware whether or not it is the same
) as the C implementation modeling it.

Why ? C operators are defined on values. They *don't care* about
the underlying binary format. You don't need to care either.


SaSW, Willem

Actually i think Tim Harig is coming at us upside down and inside out.
I suspect OP is trying to write portable C emulators for the CNC
hardware binary interfaces (to emulate machine response). This can
only partly be done. It is extraordinarily difficult to even try to
write a flexible and generic emulator for such, precisely because the
interfaces vary so much. They can take anywhere from multiple one bit
signals in a single command word to taking up to nine 32 bit integers
(or floats, or even doubles).

Then even after that much is set up there is the issue of dividing the
CNC control software drivers into machine dependant and machine
independent layers. aka Hardware Abstraction Layer (HAL).
 
J

JosephKK

On Thu, 7 May 2009 02:04:41 -0700 (PDT),
I'd have thought even if it *were* connected to a CNC machine
you could do a conversion from internal to external format
before the CNC machine saw the bits. And I'd also have thought
the conversion could be done in portable C.
I would expect so but maybe the standard language machine tool control
has died and no replacement is available. In which OP has to decode
the machine control hardware interfaces and convert to/from a standard
machine / SCADA / CNC language, perhaps like Modbus or CANBus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top