Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
20 lines (17 sloc) 1.83 KB

Operators, Expressions and Statements

  1. Write an expression that checks if given integer is odd or even.
  • Write a boolean expression that checks for given integer if it can be divided (without remainder) by 7 and 5 in the same time.

  • Write an expression that calculates rectangle's area by given width and height.

  • Write an expression that checks for given integer if its third digit (right-to-left) is 7. Example: 1732 -> true.

  • Write a boolean expression for finding if the bit 3 (counting from 0) of a given integer is 1 or 0.

  • Write an expression that checks if given point (x, y) is within a circle K((0, 0), 5).

  • Write an expression that checks if given positive integer n (n ≤ 100) is prime. Example: 37 is prime.

  • Write an expression that calculates trapezoid's area by given sides a and b and height h.

  • Write an expression that checks for given point (x, y) if it is within the circle K((1,1), 3) and out of the rectangle R(top=1, left=-1, width=6, height=2).

  • Write a boolean expression that returns if the bit at position p (counting from 0) in a given integer v has value of 1. Example: v=5; p=1 -> false.

  • Write an expression that extracts from a given integer i the value of a given bit number b. Example: i=5; b=2 -> value=1.

  • We are given integer n, value v (v=0 or 1) and a position p. Write a sequence of operators that modifies n to hold the value v at the position p from the binary representation of n. Example:

      n = 5 (00000101), p=3, v=1 -> 13 (00001101)
      n = 5 (00000101), p=2, v=0 ->  1 (00000001)
    
  • Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.

  • *Write a program that exchanges bits {p, p+1, …, p+k-1) with bits {q, q+1, …, q+k-1} of given 32-bit unsigned integer.

You can’t perform that action at this time.