Similarly casting from unsigned value u to signed

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: ding is used with floating-point numbers. End Aside. ¼¼ ¡ ¡ ¡ ¼ ½½ ¡ ¡ ¡ ½ ·¼ ¼ As an example, consider the following code: 44 CHAPTER 2. REPRESENTING AND MANIPULATING INFORMATION Weight ½ ¦ 2 4 8 16 32 64 128 256 512 1,024 2,048 4,096 8,192 16,384 ¿¾ Total 12,345 Bit Value 1 ½ 0 0 0 0 1 8 1 16 1 32 0 0 0 0 0 0 0 0 0 0 0 0 1 4096 1 8192 0 0 0 0 12,345 12,345 Bit 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 Value ½ 2 4 0 0 0 64 128 256 512 1,024 2,048 0 0 16,384 32,768 12,345 53,191 Bit Value 1 ½ 1 2 1 4 0 0 0 0 0 0 1 64 1 128 1 256 1 512 1 1,024 1 2,048 0 0 0 0 1 16,384 1 32,768 53,191 Figure 2.10: Two’s Complement Representations of 12,345 and 12,345, and Unsigned Representation of 53,191. Note that the latter two have identical bit representations. 2.2. INTEGER REPRESENTATIONS 1 2 3 4 5 45 short int x = 12345; short int mx = -x; show_bytes((byte_pointer) &x, sizeof(short int)); show_bytes((byte_pointer) &mx, sizeof(short int)); When run on a big-endian machine, this code prints 30 39 and cf c7, indicating that x has hexadecimal representatio...
View Full Document

Ask a homework question - tutors are online