avsrk@mailcity.com (Subrahmanyam Arya) wrote:
[color=blue]
> "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> wrote in message news:<3F269D89.3050302@jpl.nasa.gov>...[color=green]
> > Subrahmanyam Arya wrote:
> >[color=darkred]
> > > I am trying to solve the problem of reading the numbers correctly
> > > from a serial line into an Intel Pentium processor machine.[/color][/color][/color]
[ Snip! ]
[color=blue][color=green][color=darkred]
> > > I am thinking the same applies whether it is 1 byte, 2 byte or 4 byte
> > > quantities. IS this right .[/color]
> >
> > You are completely confused.[/color]
>
> I am not sure why ? .[/color]
Neither am I, but the symptoms are clear. You're completely confused on
signed and unsigned integers.
[color=blue][color=green]
> > You got almost everything wrong.
> > Intel uses a *2's complement* representation
> > for both positive and negative signed fixed-point (integral) types.
> > Intel uses a *sign and magnitude* representation
> > for both positive and negative floating-point types.>[/color]
>
> I know that negative integers use signed 2's complement and positive
> use signed magnitude .[/color]
I'm sorry, but there's only one description for this sentence: you're
talking out of your arse.
_Signed_ integers use _either_ 2's complement _or_ 1's complement _or_
sign magnitude. There cannot be any difference between the positive and
negative values of a signed integer in this respect, since the
difference between those methods is _how a negative number is
represented_. Positive values are identical for all three methods.
[color=blue]
> You are telling me that positive integeers use signed 2's
> complement i don't think so , i will double check on this .[/color]
No, he's telling you that _signed integers_ on an Intel machine use 2's
complement. Positive _and_ negative.
[color=blue][color=green]
> > The ANSI/ISO C standard has *no* provisions for "type casting"
> > a representation of either fixed-point or floating-point numbers
> > from one machine to an equivalent representation on another machine.
> > You will be obliged to write or purchase machine specific software
> > to implement any such conversions unless the representations
> > are identical on both machines.[/color]
>
> I am planning to write this routines , it is not two machines , one is
> a small embedded device with some microcontroller and some I/O on it ,
> the other is intel -pentium processor based PC .[/color]
So those are not two machines? What are they then, modern sculptures in
the medium of dirty silicon?
[color=blue]
> My problem is the
> analog inputs sensed by the i/o is put on the serial line by
> microcontroller in bigendian format , so i have to convert into little
> indian[/color]
One little, two little, three little indians... sorry <g>. Perhaps a
natural typo, with yout name...
[color=blue]
> apart from that i need to see if the negative numbers are put
> in signed 2's complement so that i don't have to do conversion for
> this .[/color]
Have the device send a -1 and see how it does it. Do not bother with the
positive numbers, since it makes no difference to those.
[color=blue]
> This is where i also think that positive integers are put in signed
> magnitude form on the wire[/color]
Look, I'll draw you a table, ok?
Value| 2's somp | 1's comp | sign magn
-----+----------+----------+-----------
0 | 00000000 | 00000000 | 00000000
(-0)| -- | 11111111 | 10000000
1 | 00000001 | 00000001 | 00000001
-1 | 11111111 | 11111110 | 10000001
2 | 00000010 | 00000010 | 00000010
-2 | 11111110 | 11111101 | 10000010
3 | 00000011 | 00000011 | 00000011
-3 | 11111101 | 11111100 | 10000011
14 | 00001110 | 00001110 | 00001110
-14 | 11110010 | 11110001 | 10001110
127 | 01111111 | 01111111 | 01111111
-127 | 10000001 | 10000000 | 11111111
-128 | 10000000 | -- | --
Note the complete lack of difference between the methods where positive
numbers are concerned.
[color=blue]
> and i only need to bother about byte
> ordering .[/color]
Indeed. To figure _that_ one out, have the device send the hex number
0x1234, and see if it comes through as 0x12, 0x34 or 0x34, 0x12. Then,
to make sure that it's actually big- or little-endian, and not something
muddled in between (such devices exist, oddly enough), send a four-byte
value and check that it comes back as you expect it.
[color=blue]
> Ofcourse i need to verify the fact that the intel uses
> signed magnitude for positive integers .[/color]
You will never verify that "fact", since it's not a fact, it's bollocks.
Richard