Representing and manipulating information we see that

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ction Í¾Ì Û when converting from unsigned to signed, and Ì¾Í Û when converting from signed to unsigned, where Û is the number of bits for the data type. Conversions can happen due to explicit casting, such as in the code: 1 int tx, ty; 48 2 3 4 5 CHAPTER 2. REPRESENTING AND MANIPULATING INFORMATION unsigned ux, uy; tx = (int) ux; uy = (unsigned) ty; or implicitly when an expression of one type is assigned to a variable of another, as in the code: 1 2 3 4 5 int tx, ty; unsigned ux, uy; tx = ux; /* Cast to signed */ uy = ty; /* Cast to unsigned */ When printing numeric values with printf, the directives %d, %u, and %x should be used to print a number as a signed decimal, an unsigned decimal, and in hexadecimal format, respectively. Note that printf does not make use of any type information, and so it is possible to print a value of type int with directive %u and a value of type unsigned with directive %d. For example, consider the following code: 1 2 3 4 5 int x = -1; unsigned u = 2147483648; /* 2 to the 31st */ printf("x = %u = %d\n", x, x); printf("u = %u = %d...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online