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 7967167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:37:27+00:00 2026-06-04T06:37:27+00:00

I’m adding a pair of unsigned 32bit binary integers (including overflow). The addition is

  • 0

I’m adding a pair of unsigned 32bit binary integers (including overflow). The addition is expressive rather than actually computed, so there’s no need for an efficient algorithm, but since each component is manually specified in terms of individual bits, I need one with a compact representation. Any suggestions?

Edit: In terms of boolean operators. So I’m thinking that carry = a & b; sum = a ^ b; for the first bit, but the other 31?

Oh, and subtraction!

  • 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-06-04T06:37:29+00:00Added an answer on June 4, 2026 at 6:37 am

    You can not perform addition with simple boolean operators, you need an adder. (Of course the adder can be built using some more complex boolean operators.)
    The adder adds two bits plus carry, and passes carry out to next bit.

    Pseudocode:

    carry = 0
    for i = 31 to 0
      sum = a[i] + b[i] + carry
      result[i] = sum & 1
      carry = sum >> 1
    next i
    

    Here is an implementation using the macro language of VEDIT text editor.
    The two numbers to be added are given as ASCII strings, one on each line.
    The results are inserted on the third line.

    Reg_Empty(10)                       // result as ASCII string
    #0 = 0                              // carry bit
    for (#9=31; #9>=0; #9--) {
        #1 = CC(#9)-'0'                 // a bit from first number
        #2 = CC(#9+34)-'0'              // a bit from second number
        #3 = #0+#1+#2                   // add with carry
        #4 = #3 & 1                     // resulting bit
        #0 = #3 >> 1                    // new carry
        Num_Str(#4, 11, LEFT)           // convert bit to ASCII
        Reg_Set(10, @11, INSERT)        // insert bit to start of string
    }
    Line(2)
    Reg_Ins(10) IN
    Return
    

    Example input and output:

    00010011011111110101000111100001
    00110110111010101100101101110111
    01001010011010100001110101011000
    

    Edit:
    Here is pseudocode where the adder has been implemented with boolean operations:

    carry = 0
    for i = 31 to 0
      sum[i] = a[i] ^ b[i] ^ carry
      carry = (a[i] & b[i]) | (a[i] & carry) | (b[i] & carry)
    next i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.