Questions tagged [signed-integer]

71 questions
2
votes
2 answers

What to_unsigned does?

Could someone please explain me how VHDL's to_unsigned works or confirm that my understanding is correct? For example: C(30 DOWNTO 0) <= std_logic_vector (to_unsigned(-30, 31)) Here is my understanding: -30 is a signed value, represented in bits…
1
vote
2 answers

How to access Json element with the name "long" and "short"

I am trying to access a json element with the name "long", but VS gives an error, it detects it as a 16 bit signed integer. The other elements in Json I can access , except element "long" and "short". Is there a way around this? var…
1
vote
0 answers

Signed Memory Arithmetic vulnerability iOS

I developed a Cordova application and it went through a security review, one of the findings was related to a plugin I use to make curl requests. The finding is graded as Heigh vulnerability. The finding is as follows: Signed integer sizeof at line…
1
vote
2 answers

How can I divide a signed integer using only binary operators?

I can only use ! ~ & ^ | + << >> I am writing this in C. I am trying to divide a number x by 2^n. So i thought if I shift x >> n that would work, but it does not work with odd negative integers. It originally looked like this: int dl18(int x, int n)…
pootyy
  • 55
  • 6
0
votes
0 answers

How to derive correct result when overflow occurs in 2's Complement Addition?

we can always detect overflow in 2's complement addition by certain pre-defined rules, but my question is that can I somehow find out the correct result whenever overflow condition occurs in system? we all know the Overflow detection process in…
0
votes
0 answers

subtraction of 2 sign and magnitude binary numbers in assembly (ex : 11110110 and 10101011)

how can I subtract 2 sign and magnitude binary numbers in assembly (ex : 11110110 and 10101011) I used SAL then I don't know how to pick out the sign bit, when we shift to left, our signed bit is Carry Flag. then I should use JC or JS? or ...
0
votes
0 answers

Bit shifting signed and unsigned integers

using (MemoryStream mem = new MemoryStream (bytes.Skip(4).toArray())) { using (BinaryReader reader = new BinaryReader(mem)) { UInt32 time1; UInt32 time2; Int64 time = 0; try{ time1 = reader.ReadInt32(); time2 =…
0
votes
1 answer

Idiomatically convert signed to unsigned types if you know that value will be positive

Compare the following code. It's clear from the context that one pointer will always be bigger than the other and the result of std::distance() therefore positive. How do I idiomatically convert from signed to unsigned then without having the…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
2 answers

About int and unsigned int

There are the following programs: #include int main(void) { int i=2147483647; unsigned int j=4294967295; printf("%d %d %d\n",i,i+1,i+2); printf("%u %u %u\n",j,j+1,j+2); return 0; } Why i+2 is not equal to -2147483646 ? why…
0
votes
2 answers

C usual arithmetic conversions rules

... the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands: If both operands have the same type, then no further conversion is needed. Otherwise, if both operands have signed integer…
0
votes
2 answers

Converting unsigned to signed integers (Using Excel formulas or Power Query)

I have a list of unsigned 32-bit unsigned integers that actually are supposed to represent 32-bit signed integers. For example 62714 = binary 1111010011111010 = signed -2822 when interpreted as two's complement Basically I am trying find some…
0
votes
2 answers

Unsigned modulo in Java

I'm porting some c code which is doing a modulo on an uint32_t. An uint32_t fits in a Java int bit-wise, but I cannot figure out how to perform a modulo operation on it without converting to a long. This is the code I have right now: int i =…
0
votes
0 answers

How Int class in python represent negative numbers

Do we can view, how class int in python handles negative numbers by using two's complement? I want to see source code for that not theories, I already understand how that happens in cs but I don't touch how happens in real languages. Thankful…
user14339195
0
votes
1 answer

how to print negative integer using SWORD PTR(assembly lang)

I'm learning x86 assembly language and have no idea how to print negative integer using Irvine32 library. INCLUDE Irvine32.inc .data arry SWORD 10, -20, 30 .code main PROC mov eax, 0 mov esi, OFFSET arry mov ax,…
Jasper
  • 11
  • 2
0
votes
1 answer

mod(x,y) works for unsigned integers, but not for signed integers in nand2tetris. What changes should I make?

@R2 M=0 @R0 D=M @END D, JEQ @store M=D (LOOP) @R1 D=D-M @REMAINDER D, JLT @EVENLY D, JEQ @LOOP 0, JMP (REMAINDER) @R1 D=D+M @R2 M=D (EVENLY) @store D=M @R0 …