, ,

[SOLVED] Csc160 assignment 6

$25

File Name: Csc160_assignment_6.zip
File Size: 178.98 KB

5/5 - (1 vote)

This assignment introduces bitwise-manipulation operators (&, |, <<, >>, >>>, ^, and ~), which are not discussed elsewhere in the book. The bitwise-manipulation operators perform simultaneous bit manipulations and enable programs to process large quantities of binary information efficiently. This project is here because the solution uses a conditional operator.

The binary & and | operators can implement bitwise “and” and “or” operations on corresponding bits in a pair of 32-bit int operands. This bit-manipulation capability enables Java to efficiently process large quantities of raw binary information. We use this capability to encrypt information sent over the Internet and to process graphical images. Suppose you have a 32-bit pattern of 1’s and 0’s in an integer called mask. You can use mask to either set to 1 or reset to 0 any subset of the bits in another integer called data:

In particular, you can use a mask having only one 1 bit to see if that particular bit is 1 in data. If (mask & data) != 0, that data bit is 1. If (mask & data) == 0, that data bit is 0.

The << shift-left operator shifts the bit pattern to the left by a number of bits indicated by the operand to the right of the operator, and it shifts zero into the right end. Each left shift multiplies the numerical value of the int operand by 2. The >> arithmetic shift-right operator shifts the bit pattern to the right by a number of bits indicated by the operand to the right of the operator. To preserve the sign, it shifts into the left end whatever was there before. Each arithmetic-right shift divides the numerical value of the int operand by two. The >>> logical shift-right operator shifts the bit pattern to the right by a number of bits indicated by the operand to the right of the operator, and it shifts zero into the left end. The >>> operator is the logical opposite of the << operator.

Java also includes a complement operator, ~. The complement operator simply reverses the polarity of all bits in the following int operand. Each bit that is 1 becomes 0, and each bit that is 0 becomes 1. For example, if number is initially 0, ~number is -1, and vice versa.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Csc160 assignment 6[SOLVED] Csc160 assignment 6
$25