Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,600 members, 7,809,179 topics. Date: Friday, 26 April 2024 at 03:20 AM

Write An Algorithm To Add N Binary Numbers - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Write An Algorithm To Add N Binary Numbers (1308 Views)

Help Construct An Algorithm In Php Code / Your Toughest Algorithm / Help Out With Algorithm To Add Multiple Numbers (2) (3) (4)

(1) (Reply) (Go Down)

Write An Algorithm To Add N Binary Numbers by Princefame1: 9:43pm On Jul 01, 2015
Programmers in the house help me answer the above question.
Re: Write An Algorithm To Add N Binary Numbers by Fulaman198(m): 1:04am On Jul 02, 2015
Not sure what the problem here is stated

some function would probably be

What are you trying to do?
Re: Write An Algorithm To Add N Binary Numbers by Princefame1: 4:02am On Jul 02, 2015
Fulaman198:
Not sure what the problem here is stated
some function would probably be
What are you trying to do?
. Is just an algorithm to add binary numbers..
Re: Write An Algorithm To Add N Binary Numbers by FincoApps(m): 5:34am On Jul 02, 2015
I suggest you try something first and show us. It would be wrong for people to just do the whole assignment for you. And what language are you working with ?
Princefame1:
Programmers in the house help me answer the above question.

1 Like 1 Share

Re: Write An Algorithm To Add N Binary Numbers by Princefame1: 10:33am On Jul 02, 2015
FincoApps:
I suggest you try something first and show us. It would be wrong for people to just do the whole assignment for you. And what language are you working with ?

I just need an algorithm to add binary numbers, dnt really need it in any programming language.

1 Like

Re: Write An Algorithm To Add N Binary Numbers by FincoApps(m): 11:27am On Jul 02, 2015
Oh okay.
What I would do is
- Convert the numbers to decimal first (You can store 128, 64, 32, 16, 8, 4, 2, 1) in an int array and add all the indexes of 1s together
- Add the decimals together.
- Convert the result back to binary

Note: Converting to decimal with the above method works for numbers less than 256. If you want to make it better, you can create the array dynamically.

Princefame1:


I just need an algorithm to add binary numbers, dnt really need it in any programming language.

1 Like

Re: Write An Algorithm To Add N Binary Numbers by Fulaman198(m): 12:43am On Jul 06, 2015
FincoApps:
Oh okay.
What I would do is
- Convert the numbers to decimal first (You can store 128, 64, 32, 16, 8, 4, 2, 1) in an int array and add all the indexes of 1s together
- Add the decimals together.
- Convert the result back to binary

Note: Converting to decimal with the above method works for numbers less than 256. If you want to make it better, you can create the array dynamically.


That's a start for him

a very good start

I advise that he proceeds from there.

So here is what he should do to begin:

Output: Ask user to enter a "x" number of values to be added
Input x
Output: Which decimal values would you like to add "y"
Input the decimals

Create a function like you stated to convert the decimal values to binary (an array preferably) in which

128 64 32 16 8 4 2 1 are utilised


Remember Binary is based on Power of 2 logic.

So for instance a Value like 225 would be 11100001 in Binary

I advise that he adds the values in decimal first before converting them to binary. That is easier that way in my opinion. There are different ways to go about this problem.
Re: Write An Algorithm To Add N Binary Numbers by Ogbeozioma: 6:32am On Jul 07, 2015
U can also convert to decimal by taking the binary digit and take the remainder when you divide it by 10 , that would give you the last digit, then multiply by 2power0, the get the next digit by dividing by 10 again and multiply by 2power 1. Continue doing this while the binary nuber is greater than zero. Then add everything. Hope yo got it.
Re: Write An Algorithm To Add N Binary Numbers by Ogbeozioma: 6:33am On Jul 07, 2015
U can also convert to decimal by taking the binary digit and take the remainder when you divide it by 10 , that would give you the last digit, then multiply by 2power0, then get the next digit by dividing by 10 again and multiply by 2power 1. Continue doing this while the binary nuber is greater than zero. Then add everything. Hope yo got it. This would convert larger number depending on you type of variable, but they should always be integer type.
Re: Write An Algorithm To Add N Binary Numbers by Princefame1: 10:26pm On Sep 17, 2022
@Wittylander,
I don't seem to get you contact number correctly.

I have some questions I need to get clarification on regarding the importation of laptops. Thanks.

(1) (Reply)

Freelance Web Developers And Software Engineers Urgently Needed / Tech Gurus, Advice Needed Pleased / Please Rate My Nairaland.com Front Page Mock Design In HTML/CSS/JS

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.