LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to add two 4-bit numbers (https://www.linuxquestions.org/questions/programming-9/how-to-add-two-4-bit-numbers-4175445961/)

curious95 01-16-2013 11:50 PM

How to add two 4-bit numbers
 
How do i add two four bit numbers, what are the steps required to do so?

linosaurusroot 01-17-2013 12:27 AM

What kind of equipment is available? Are you looking for a chart of NAND gates or a line of a C program or what?

curious95 01-17-2013 12:37 AM

No ,nothing like that, just how do i add two four bit numbers manually on paper. Like 0000 + 0001.

laho 01-17-2013 12:58 AM

0000
0001
----
0001

It's the same like adding decimal numbers. The same rules apply.

curious95 01-17-2013 01:10 AM

Quote:

Originally Posted by laho (Post 4871905)
0000
0001
----
0001

I don't think so i'm talking about binary addition(base 2). I don't know how to do it. But i could use an example showing me what to do.

linosaurusroot 01-17-2013 07:18 AM

In decimal when you get to 10 you write a single digit in the current column and carry 1 to the next column (left, more significant). Binary is just the same except it's 2 that brings you to the carry - there are only two single digits 0 and 1.

danielbmartin 01-17-2013 07:31 AM

Quote:

Originally Posted by curious95 (Post 4871882)
How do i add two four bit numbers, what are the steps required to do so?

There are on-line tutorials. This is a good one:
http://www.math.grin.edu/~rebelsky/C...student-binary

Daniel B. Martin

dwhitney67 01-17-2013 08:04 AM

Quote:

Originally Posted by curious95 (Post 4871915)
I don't think so i'm talking about binary addition(base 2). I don't know how to do it. But i could use an example showing me what to do.

An example was already given.

Here's a few other examples:
Code:

    0010
+  0101
  ------
    0111


    0011
+  0001
  ------
    0100


    0101
+  1011
  -------
    0000    <--- Note in this example, the most significant bit of the result rolled out of existence.


sundialsvcs 01-17-2013 08:58 AM

It's exactly like base 10: 0 + 1 = 1 ... etc[/b] ... 1 + 1 = 1 carry 1.

It does take a bit of getting used two ... ;)

linosaurusroot 01-17-2013 10:29 AM

http://cowbirdsinlove.com/43

suicidaleggroll 01-17-2013 10:32 AM

It's the same as adding in any other base. Base 2, base 8, base 10, base 16, it all works the same.

Start at the LSB, add the numbers together. If you overflow that digit (2 in base 2, 8 in base 8, 10 in base 10, etc), then carry the 1 into the next most significant column and repeat.

suicidaleggroll 01-17-2013 10:33 AM

Quote:

Originally Posted by linosaurusroot (Post 4872270)

lol, clever

273 01-17-2013 10:36 AM

Like the much repeated phrase "There are 10 types of people in the world: those that understand binary and those that don't.".

curious95 01-17-2013 01:07 PM

Thank you, i've understood what to do :) Sorry laho guess i thought binary addition would be 'harder' than that.

jlinkels 01-17-2013 08:49 PM

Quote:

Originally Posted by curious95 (Post 4872382)
Thank you, i've understood what to do :) Sorry laho guess i thought binary addition would be 'harder' than that.

Try subtraction :)
jlinkels

laho 01-17-2013 11:46 PM

Quote:

Originally Posted by curious95 (Post 4872382)
Thank you, i've understood what to do :) Sorry laho guess i thought binary addition would be 'harder' than that.

No prob. That's why computers use it because it's easy to do.

curious95 01-17-2013 11:50 PM

Good idea will check it out.

Sergei Steshenko 01-20-2013 03:37 PM

Quote:

Originally Posted by curious95 (Post 4871882)
How do i add two four bit numbers, what are the steps required to do so?

Start from here: https://en.wikipedia.org/wiki/Positional_notation .


Modern world appears to be completely dumbed down - we were taught the above at school, before age of 17.

Sergei Steshenko 01-20-2013 03:39 PM

Quote:

Originally Posted by laho (Post 4872643)
No prob. That's why computers use it because it's easy to do.

No.

Computers don't care - they are not humans.

jlinkels 01-20-2013 05:22 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4874259)
Start from here: https://en.wikipedia.org/wiki/Positional_notation .


Modern world appears to be completely dumbed down - we were taught the above at school, before age of 17.

This is severely OT, but the description of number systems reminded me of former employer I worked for. The owner of that company was a genius, but also of a bit a nerd as happens so often with smart people. Our workstations were W 3.11, but for the servers etc he insisted on Solaris. This was 1992, so Linux was not really widespread.

He insisted on a standard file name convention, wich was FILENAME.YMD. 8.3 filenames only, remember? So to write YMD, we used that last digit of the year, the month in base-12, and the day in base-31. Base-31 is not difficult, just continue to use alphanumerics after F... After some practicing most of us could remember the ordinals of the characters by heart. I have been using this base-31 file extensions for many years after that, until the 8.3 filenames completely disappeared.

jlinkels

suicidaleggroll 01-20-2013 08:48 PM

Quote:

Originally Posted by jlinkels (Post 4874315)
He insisted on a standard file name convention, wich was FILENAME.YMD. 8.3 filenames only, remember? So to write YMD, we used that last digit of the year

It is amazing how many programmers still use this incredibly short-sighted practice. Not just single digit years, 2 digit years are nearly as bad. In the next 40 years we are going to be facing a shitstorm of "if (2digityear < 50) then 4digityear=2digityear+2000 else 4digityear=2digityear+1900" breakdowns across the board. Even now, when file name and memory space restrictions are almost non-existent, I still see programmers using this practice all over the place.

It gets me all worked up...sorry about the tangent.

jlinkels 01-20-2013 09:01 PM

I think you are right about the laziness/shortsightedness of certain programmers, but with 8.3 filenames there was little other choice. Maybe 8.3 was not such a good idea.

jlinkels

theNbomr 01-22-2013 01:37 PM

Quote:

Originally Posted by sundialsvcs (Post 4872207)
It's exactly like base 10: 0 + 1 = 1 ... etc[/b] ... 1 + 1 = 1 carry 1.

It does take a bit of getting used two ... ;)

I think that should be 1 + 1 = 0 carry 1.

My inner pedant emerges again. Someone should have noticed that after the old "10 people...." thing came up.

While tempting to bash Microsoft for the whole 8.3 filename thing, I'm fairly sure it was a deliberate choice to be compatible with CP/M.

--- rod.


All times are GMT -5. The time now is 10:21 PM.