Questions tagged [signed-integer]

71 questions
3
votes
1 answer

Signed int in c language assignd bitfields but confusion

Currently I am working on c and facing a confusion regarding signed int in structure and here I have given the example: #include #include struct { signed int age : 4; } Age; int main( ) { Age.age = -8; printf("Age.age…
3
votes
3 answers

C - Get smallest possible signed integer

Is there anything similar to Java's Integer.MIN_VALUE in C, which gives the smallest possible value of a signed integer, or do I just have to hard code the value myself?
0x56794E
  • 20,883
  • 13
  • 42
  • 58
2
votes
1 answer

Doing calculation in the range 0f 10^30

The following code is giving an error by saying the message "singed integer overflow". And the error is in this test case : input : 208170109961052 Output : 4611790103482368430 Expected Output : 104085054980526 The input range is…
2
votes
2 answers

Why, in some C++ compilers, does `int x = 2147483647+1;` give only a warning but stores a negative value, while some compilers give a runtime error?

I want to check if the reverse of an signed int value x lies inside INT_MAX and INT_MIN. For this, I have reversed x twice and checked if it is equal to the original x, if so then it lies inside INT_MAX and INT_MIN, else it does not. But online…
UNREAL
  • 430
  • 5
  • 11
2
votes
2 answers

С typecasting in conditions

There is a simple example: unsigned a = -5; int b = 5; if (a + b <= -1){ ... } To which type will cast a+b? To signed or unsigned? And is it noted in C-standard or compiler will decide what to do?
2
votes
2 answers

Unsigned user-defined integer literal

Suppose I want to define an integer literal which also allows for negative values, e.g. -12_km. I.e., I would like to do using coord_t = long long; coord_t operator "" _km(long long int); However, this is not accepted by my compiler (gcc). The…
2
votes
2 answers

How to convert negative integer to string and output it in MASM Assembly

I am supposed to take signed integers from a user, calculate the sum of inputted numbers and then display the average. The problem is, negative numbers don't seem to be displaying correctly, although I know the sum and average are being calculated…
halpme
  • 17
  • 3
2
votes
3 answers

Convert two bytes to a signed integer in java

Question in short Is there a way to read two bytes as a signed integer? Details & example Given two bytes in java, each represents an integer, we can convert them to the int value they represent together by simply: byte[] byteArray = new…
Othman H
  • 75
  • 2
  • 9
2
votes
2 answers

Assembly imul signed

thx for help my question is about ax value received from code below? mov al,22h mov cl,0fdh imul cl Actual machine result: ff9a What I expected: 00:9a (by multiplying in binary) The first number is 22h so its 34 decimal its already unsigned the…
Hai Vaknin
  • 37
  • 1
  • 8
2
votes
2 answers

Unreasonable behavior on mixing signed and unsigned integers

Motivated from a code snippet on this blog under "What happens when I mix signed and unsigned integers?" I decided to run it with few different values of signed and unsigned integers and observe the behaviour. Here is the original snippet (slightly…
user3276435
  • 265
  • 1
  • 3
  • 13
2
votes
3 answers

Which string hashing algorithm produces 32-bit or 64-bit signed integers?

I want to hash strings of variable length (6-60 characters long) to 32-bit signed integers in order to save disk space in PostgreSQL. I don't want to encrypt any data, and the hashing function needs to be reproducible and callable from Python. The…
tryptofame
  • 352
  • 2
  • 7
  • 18
2
votes
4 answers

If we add one to the largest re-presentable integer, is the result negative?

This program is asking the C implementation to answer a simple question: If we check the largest re-presentable integer INT_MAX < 0 and print it. printf ("%d\n", (INT_MAX) < 0); So, displayed output 0. because condition become false and…
msc
  • 33,420
  • 29
  • 119
  • 214
2
votes
2 answers

How can I store numbers > 128 in a signed one byte interger?

I am reading the book Art of Assembly Language. There I came across this paragraph. If the H.O. bit is zero, then the number is positive and is stored as a standard binary value. If the H.O. bit is one, then the number is negative and is…
narayanpatra
  • 5,627
  • 13
  • 51
  • 60
2
votes
1 answer

How to avoid trap representations when doing XOR bit-cancellation on signed ints?

As as suggested solution for Given three numbers, find the second greatest of them, I wrote: int second_largest(int a, int b, int c) { int smallest = min(min(a, b), c); int largest = max(max(a, b), c); /* Toss all three numbers into a…
200_success
  • 7,286
  • 1
  • 43
  • 74
2
votes
2 answers

Why is the "sign bit" included in the calculation of negative numbers?

I'm new to Swift and is trying to learn the concept of "shifting behavior for signed integers". I saw this example from "the swift programming language 2.1". My question is: Why is the sign bit included in the calculation as well? I experienced…
Thor
  • 9,638
  • 15
  • 62
  • 137