32 Bit Signed Integer Addition in C

Here is my program: int main() { int32_t a = 2147483647; int32_t b = -214783648; int32_t s = a + b; printf("%d\n", s); } I expected this to be -1 with no overflow, but my output is this: 1932699999. Does anyone know why? ...
more »

2017-02-13 01:02 (0) Answers

R Vector Values Overwrite in Function

specific problem i'm solving: Create a character vector with length of number-of-rows-of-iris-dataset, such that, each element gets a character value – “greater than 5″ if the corresponding ‘Sepal.Length’ > 5, else it should get “lesser...
more »

2017-02-11 21:02 (1) Answers

Compare quotient of two integers

I am using fixed point code (i.e. only 16 and 32-bit integers). Now I need to compare the quotient of two integers, which are very similar, e.g. int result = 705/239; int result2 = 720/235; How could I tell which of the results would be larger by ...
more »

2017-02-10 10:02 (2) Answers

Randomizing part of array in C#

Lets say I have an array of integers. I found out that I can randomize the order of the elements simply by doing: Random rnd = new Random(); array = array.OrderBy(x => rnd.Next()).ToArray(); But lets say I want to keep the first and the last el...
more »

2017-02-09 14:02 (5) Answers

How to convert an IBAN to an Integer?

Note, this is not about using libraries or any specific programming language. I just want to understand the following concept, from Wikipedia, Validating the IBAN: Example (fictitious United Kingdom bank, sort code 12-34-56, account number 987654...
more »

2017-02-09 13:02 (1) Answers

signed integer, arithmetic shift to the left

I'm trying to understand how "signed integer" and "arithmetic left shift" works in swift and iOS. In the book, swift programming language 3.0, it says I tried it out with the following code: I understand with signed integer, binary represent...
more »

2017-02-09 03:02 (1) Answers

Functions and random integers

I want to first say this is my homework, so I do not want it done for me I just need some guidance as my teacher is not providing it for me nor can I find my answer online. Here is my problem Write a program that displays a table of distance equiva...
more »

2017-02-09 03:02 (0) Answers

Swift: Why can't I add 2 integers here?

I'm new to Swift. I'm using Swift 3.x in Xcode. After struggling to take input from an outlet, I finally managed to work through most of the errors and now I've come to the strangest thing ever. How can I not sum 2 integers?? The goal: Monte Carlo I...
more »

2017-02-08 00:02 (3) Answers