From: Benjamin on 8 Jul 2010 18:21 How is two's complement represented in a header file? How is two's complement different than int8 or is it different? How do you create/used the data type two's complement in simulink?
From: James Tursa on 8 Jul 2010 18:35 "Benjamin " <bcpotter(a)iastate.edu> wrote in message <i15j0i$nd6$1(a)fred.mathworks.com>... > How is two's complement represented in a header file? What header file? I have no idea how to interpret this question. > How is two's complement different than int8 or is it different? 2's complement is one way to represent integers at the bit level. MATLAB happens to run on machines that use this system, so int8 on those machines will naturally be 2's complement at the bit level on those machines. James Tursa
From: Steve Amphlett on 9 Jul 2010 04:21 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <i15jr8$g4o$1(a)fred.mathworks.com>... > "Benjamin " <bcpotter(a)iastate.edu> wrote in message <i15j0i$nd6$1(a)fred.mathworks.com>... > > > How is two's complement represented in a header file? > > What header file? I have no idea how to interpret this question. > > > How is two's complement different than int8 or is it different? > > 2's complement is one way to represent integers at the bit level. MATLAB happens to run on machines that use this system, so int8 on those machines will naturally be 2's complement at the bit level on those machines. > > James Tursa You can explore two's complement using Matlab's <typecast> function. For example, what is the two's complement of 100 (i.e. the int8 representation for -100)? 100(dec) = 01100100(bin) Flip the bits: 10011011 Add 1: 10011100 So 10011100 is the bit representation of the int8: -100 To test: 10011100(bin) = 156(dec) >> typecast(uint8(156),'int8') ans = -100 >> typecast(int8(-100),'uint8') ans = 156
From: Benjamin on 9 Jul 2010 08:02 > > How is two's complement represented in a header file? > > What header file? I have no idea how to interpret this question. > The header file I was referring to was the one generated after compiling a simulink model into C using RealTimeWorkshop; I should have been more specific. > > How is two's complement different than int8 or is it different? > > 2's complement is one way to represent integers at the bit level. MATLAB happens to run on machines that use this system, so int8 on those machines will naturally be 2's complement at the bit level on those machines. I think this answers my questions; int8 is effectively two's complement. Thanks!
|
Pages: 1 Prev: colorbar title Next: Formatting the Dates on imported data |