221 integral data types c supports a variety of

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: ft end with 0s. The shift amount should be a value between ¼ and Ò ½. Shift operations group from left to right, so x << j << k is equivalent to (x << j) << k. Be careful about operator precedence: 1<<5 - 1 is evaluated as 1 << (5-1), not as (1<<5) - 1. There is a corresponding right shift operation x >> k, but it has a slightly subtle behavior. Generally, machines support two forms of right shift: logical and arithmetic. A logical right shift fills the left end with 0s, giving a result ¼ ¼ ÜÒ ½ ÜÒ ¾ Ü . An arithmetic right shift fills the left end with repetitions of the most significant bit, giving a result ÜÒ ½ ÜÒ ½ ÜÒ ½ ÜÒ ¾ Ü . This convention might seem peculiar, but as we will see it is useful for operating on signed integer data. The C standard does not precisely define which type of right shift should be used. For unsigned data (i.e., integral objects declared with the qualifier unsigned), right shifts must be logical. For signed data (the...
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