All Posts

How to Find the Larger Number Without Conditional Operators Part 2 (Arithmetic)

Given two (2) signed integer numbers, A and B. Find the larger number between these two (2) variables, using only arithmetic expressions. Provide a solution to the following:

  1. Assign 0 to X, if A = B, or assign the larger number between A and B
  2. Assign the larger number between A and B to Y, or assign either A or B, if A = B

How to Find the Larger Number Without Conditional Operators Part 1 (Using Bitwise Operators)

Given two (2) signed integer numbers, A and B, where:

  • size = ( Integer size int = 4 bytes* = 32 bits ) - 1
  • -2size ≤ A ≤ 2size-1, and
  • -2size ≤ B ≤ 2size-1

Find the larger number between variables A and B, without using conditional operators. Provide a solution to the following:

  1. Assign 0 to X, if A = B, or assign the larger number between A and B
  2. Assign the larger number between A and B to Y, or assign either A or B, if A = B

Pages