addition

Why does addition of long variables cause concatenation?

What does Java do with long variables while performing addition? Wrong version 1: Vector speeds = ... //whatever, speeds.size() returns 2 long estimated = 1l; long time = speeds.size() + estimated; // time = 21; string concatenation?? Wrong version 2: Vector speeds = ... //whatever, speeds.size() returns 2 long estimated = 1l; long ...

What is the best way to add two numbers without using the + operator?

A friend and I are going back and forth with brain-teasers and I have no idea how to solve this one. My assumption is that it's possible with some bitwise operators, but not sure. ...

fetching html that is actually a number, want to add 1 to it and replace it

Hi, i'm trying to add 1 to a value that I fetched from my HTML using jquery. At the moment it is appending 1, treating the value as a string. ...

add two double given wrong result

I'm using the following piece of code and under some mysterious circumstances the result of the addition is not as it's supposed to be: double _west = 9.482935905456543; double _off = 0.00000093248155508263153; double _lon = _west + _off; // check for the expected result Debug.Assert(_lon == 9.4829368379380981); // sometimes i get 9.48...

What's better multiplication by 2 or adding the number to itself ? BIGnums

I need some help deciding what is better performance wise. I'm working with bigints (more then 5 million digits) and most of the computation (if not all) is in the part of doubling the current bigint. So i wanted to know is it better to multiply every cell (part of the bigint) by 2 then mod it and you know the rest. Or is it better just...

C++ string addition

Simple question: If I have a string and I want to add to it head and tail strings (one in the beginning and the other at the end), what would be the best way to do it? Something like this: std::string tmpstr("some string here"); std::string head("head"); std::string tail("tail"); tmpstr = head + tmpstr + tail; Is there any better way ...

Why is subtraction faster than addition in Python?

I was optimising some Python code, and tried the following experiment: import time start = time.clock() x = 0 for i in range(10000000): x += 1 end = time.clock() print '+=',end-start start = time.clock() x = 0 for i in range(10000000): x -= -1 end = time.clock() print '-=',end-start The second loop is reliably faster, anyw...

SQL Table vs Table Addition

Is it possible to craft a query that adds values within two tables: For example, say you have two tables id value -- ----- a 1 c 2 d 3 f 4 g 5 and id value -- ----- a 1 b 2 c 3 d 4 e 5 Then when you 'add' the two tables you would get the result where t...

Time calculation in php (add 10 hours)?

I get the time: $today = time(); $date = date('h:i:s A', strtotime($today)); if the current time is "1:00:00 am", how do i add 10 more hours to become 11:00:00 am?? ...

One's complement instead of just a sum of bits

A question in my university homework is why use the one's complement instead of just the sum of bits in a TCP checksum. I can't find it in my book and Google isn't helping. Any chance someone can point me in the right direction? Thanks, Mike ...

Calculate exponents via addition only

We're writing a very simple program to execute on a processor we've built for a class. It doesn't have the capability to multiply or divide. We do however, had support for addition, subtraction, and, or, and branching for loop control (like branch on equal if you are familiar with MIPS). We were thinking a neat program to run on it would...

how to add content of word doc file in jsp file using include action?

I am trying to include the text content of microsoft word file in my jsp file.... I am not able to figure out the solution. ...

Overflow and Carry flags

Is it possible to add two signed 8-bit numbers together and set both the carry and overflow bits? ...

Binary Addition of 2 values ( there is a catch :D) C# - RESOLVED

hey guys , im doin a final year project but it has come to a dead end as i dont know any way i can perform binary addition in C# what i am trying to do is i have two strings string a= "00001"; /* which is decimal 1 i made it with the '0's using string a = Convert.ToString(2, 2).PadLeft(5, '0'); */ string b= "00010"; what i want to...

Include or Exclude existing files/directories from current solution

Hi thr..How can i include or exclude existing files/directories from current solution in c sharp through code.. ...

How to make += operator keep the object reference?

Say, I have a class: class M { public int val; And also a + operator inside it: public static M operator +(M a, M b) { M c = new M(); c.val = a.val + b.val; return c; } } And I've got a List of the objects of the class: List<M> ms = new List(); M obj = new M(); obj.val = 5; ms.Add(obj); ...

addition without arithmetic and bitwise operators

how to add 2 numbers without using + and bitwise operators? ...

Summing values from datagrid

I am developing an e-commerce system as my project and have a datagrid acting as my shopping cart. it has two columns book and listPrice. the question is i want to sum the values in the listPrice column while the output is displayed in a label. Can someone please show me how to do this. Your help is much appreciated ...

Looping through columns in a .csv files in Python

I want to be able to use Python to open a .csv file like this: 5,26,42,2,1,6,6 and then perform some operation on them like addition. total = 0 with open("file.csv") as csv_file: for row in csv.reader(csv_file, delimiter=','): for number in range(7): total += int(row[number]) The problem is tha...

Most efficient way to combine two objects in C#

I have two objects that can be represented as an int, float, bool, or string. I need to perform an addition on these two objects with the results being the same thing c# would produce as a result. For instance 1+"Foo" would equal the string "1Foo", 2+2.5 would equal the float 5.5, and 3+3 would equal the int 6 . Currently I am using th...