Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6085897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:41:28+00:00 2026-05-23T11:41:28+00:00

is there a simple way to find the smaller of two binary numbers (signed

  • 0

is there a simple way to find the smaller of two binary numbers (signed in two’s complement format), with only the following operations: bitwise logic, right shift, an add, an equality compare, and a jump if accu is negative?

I need this for an assignment to express some C snippets in a very minimal assembler language.

The only thing I came up with so far is a distinction of 3 cases:

  1. If one number is negative and the other positive we have the solution there.

  2. If both numbers are positive, add to both minus one and check for the first number to get zero, this is the smaller one.

  3. If both are negative, make them positive i.e. take the two’s complement of both and go to step 2.

But this seems rather extensive for a “simple” less than condition.

Maybe I am just stupid and can’t see the obvious solution 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:41:28+00:00Added an answer on May 23, 2026 at 11:41 am

    Okay, first of all, you do know this is possible — those operations are all there really is for bit manipulation. So what’s, first of all, the simplest possible thing? A loop like this

    loop
      Set A to one closer to zero
      Set B one closer to zero
    until either A is 0 or B is zero
    

    When you get either A or B to zero, then that one is the smaller. Observe that this works for either two negatives or two positives. So now you have a known solution; conveniently, you have an add instruction so you don’t need to implement that.

    But that’s O(n). What can you do better? (Hint: you should be able to get O(lg n).)

    Consider what a right-shift is in a binary number: it’s essentially division by 2.

    See if that hint helps any.

    Here’s an alternate thought: if you have a word-width add, how can you turn an addition into a subtraction? If you can do that,. you can subtract A from B and see how the difference comes out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple and clean jQuery way to find the element who a
Is there a simple way to find the current version of my application from
is there a simple way to find out if a checkbox is checked in
Is there a simple way to find a file on my desktop in Emacs?
Given a .so file and function name, is there any simple way to find
Is there any simple way to find broken ntfs symbolic links in windows and
Is there any fast way to find the largest power of 10 smaller than
Is there a simple way to find out what versions of dependencies are available
I got two timestamps in unix format and I need to find a way
Is there a simple way to find out if a property grid is currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.