Skip to main content

Questions tagged [integers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
16 views

Why does negation flip all high bits of a number expect for the least significant bit?

In his blog post on 512 bit division, Remco Bloemen makes the following assertion: ... negation flips all high bits of a number up to but not including the least significant one Why is that?
Paul Razvan Berg's user avatar
0 votes
1 answer
71 views

Complicated ERC20 Arithmetic

I'm trying to compose a formula in Solidity that has a combination of unsigned integers, signed and exponents, however having a hard time figuring out how to do so. The formula would look something ...
teh0wner's user avatar
  • 101
0 votes
1 answer
444 views

How absolute value work in solidity? [duplicate]

For some reason, I will get two values which are uint256. How do I calculate uint256 then get the absolute value? uint256 a = 5; uint256 b = 9; return a-b; // will be return 4 return b-a; // will be ...
leojail's user avatar
  • 177
1 vote
1 answer
614 views

How to convert default two's complement representation to sign magnitude form?

According to this answer the EVM by default uses two's complement notation for handling signed integers. However for my application I would like to work with the sign-magnitude representation where ...
MShakeG's user avatar
  • 1,663
4 votes
1 answer
1k views

How do you handle the hex prefix without the value (only "0x")?

First, I'm caling function foo() (from another contract) that returns me a uint in the form of bytes. Then, I'm using BytesLib.toUint(foo(), 0) to retrieve the uint. When the value is supposed to be 1,...
António Gonçalves's user avatar
2 votes
2 answers
488 views

What is the fastest way to check the sign of an int256 in Solidity?

Given an int256 number n, I want to get the sign of n: If n is positive, get 1 If n is negative, get -1 If n is 0, get 0 I know that I can do: function foo(int256 x) external { if (x > 0) { ...
Paul Razvan Berg's user avatar
0 votes
0 answers
809 views

Validation of integers on solidity

I have this function and require the _price variable to be positive, But when I pass a negative int, it accepts the integer! How can I validate the input? The Contract : function createProduct(string ...
Pooya Taheri's user avatar
1 vote
1 answer
2k views

How to get absolute value in solidity?

In JavaScript, there is "Math.abs": Is there a similar function in solidity itself or some other popular library such as SafeMath?
Paul Razvan Berg's user avatar
1 vote
1 answer
479 views

How to verify the sha256 result of integer 5 in the Zokrates tutorial?

The Zokrates tutorial here starts with calculating the SHA256 hash of (the number) 5. The hex representation of the result is shown at the bottom here: However, I could not reproduce this on my ...
Ytsen de Boer's user avatar
4 votes
1 answer
833 views

Synthetic uint512 out of 2 uint256

If I were trying to make a synthetic unsigned integer_512, but the largest supported integer in Ethereum is u256, how would I combine 2 u256 to make a single u512 in solidity? If I were also looking ...
Mittenchops's user avatar
-1 votes
1 answer
57 views

what is the different between this two? [closed]

today I have two type One is like this pragma solidity ^0.5.0; contract Test{ function TestVar() view public returns(uint8){ uint8 a; for(uint8 b=0;b<20; b++){ a=b; } ...
user50988's user avatar
0 votes
1 answer
103 views

Why doesn't Solidity throw an error for overflows? [duplicate]

It seems like there are going to be a lot of people that forget to check for integer overflows in Solidity. I am wondering if there is a reason why Solidity doesn't throw errors for integer overflows ...
Alexis's user avatar
  • 149
0 votes
1 answer
503 views

Increment a uint variable results in unexpected value

I have the function resolveProject() in my contract, which iterates over a list of Task, let's say 2, both with status 3. function resolveProject() { // ... uint closedTask; uint ...
Zeta's user avatar
  • 13
0 votes
2 answers
442 views

Solidity: uint parameter not being set properly

Testing my contract locally with truffle. I have a function with the signature: function purchase(address buyer, address seller, bytes16 bookId, uint tokens) public onlyOwner returns(bool success) ...
Simon Rubin's user avatar
1 vote
1 answer
933 views

Truffle test: inputting an uint256 outputs a different result

To simplify my question, let's say I have a Test.sol with a function that simply output the input: function testFunc(uint256 value) public pure returns (uint256) { return value; } Now I want to ...
Richard Fu's user avatar
0 votes
2 answers
2k views

How to store a Big Number?

I need to determine an expiry date for a contract a for this I use the foloowing code as the constructor of the contract : constructor(address _recipient, uint256 duration) public ...
Questioner's user avatar
  • 2,670
1 vote
1 answer
969 views

negative numbers passed to view functions are treated differently to negative numbers passed to transaction functions

Using solidity 0.4.18 I have the following contract: contract MyContact { mapping(address => uint) private balances; modifier positiveNumber(uint number) { require(number > 0);...
Dave Sag's user avatar
  • 879
30 votes
2 answers
105k views

What is uint256?

With regard to Solidity, What is UINT256? From the token example at https://ethereum.org/token : /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; ...
Bruce Seymour's user avatar
14 votes
2 answers
17k views

Max/min values of standard data types

Where can I find the maximum and minimum values that various types can store? And an epsilon value for floats? I'm looking for something like C's limits.h, but for Solidity / EVM.
Tom Hale's user avatar
  • 3,107
0 votes
0 answers
370 views

Invalid opcode during division

I have seen many posts around the division operation in Solidity e.g. Cant' do any integer division. Firstly, the error I am facing is different. Secondly, I am ensuring that, all numbers in division ...
cogitoergosum's user avatar
1 vote
2 answers
175 views

Can it be shown that `num > 0 && num < denom` is always the same as 0% < num / denom < 100%?

In Solidity, I want to check that the numerator and denominator passed to my function evaluate to 0% < num / denom < 100%. I tried the most direct approach: num / denom > 0 && num / ...
Will White's user avatar
27 votes
4 answers
22k views

Can't do any integer division

I'm building a new smart contract but really can't figure out how to perform integer division. I know that fixed point numbers haven't been implemented yet but it should be possible to perform 100/3 = ...
Hugo Moreau's user avatar
3 votes
1 answer
806 views

How to store negative values inside {8||16||32} bits in populus?

I want to store -1 in smallest memory such as in {8||16||32} bits instead of 256 bits. int i = -1; When I return var, it returns -1L instead of -1. I have assigned -1 into a int8 variable. As I ...
alper's user avatar
  • 8,395
8 votes
3 answers
5k views

Type casting msg.value to uint248

I am new to solidity programming and sorry if my question is very basic. I am wondering if we can cast msg.value to uint248 Example below ; uint value; value = (uint248) (msg.value);
Deepa's user avatar
  • 241
1 vote
2 answers
636 views

Not able to read data from smart contracts

I am doing PoC on Ethereum using Azure Ethereum network and Web3. I was working from last 1 month and I have created one smart contract for student management and that was working like fab. But for ...
Sagar's user avatar
  • 29
2 votes
0 answers
106 views

VM jump when accessing statically set variables

Hey it seems I get a jump error when I try to access any variable not set through a parameter in the constructor. amountRaised is throwing a jump error below as I try to statically set the value. ...
ethereal's user avatar
  • 1,805
8 votes
1 answer
1k views

Difference between the assembly code generated for uint and uint32?

I wrote a simple contract with a single state variable with type uint and the generated assembly code is quite straight forward. But when I changed the type to uint32 the generated assembly becomes ...
Shamik's user avatar
  • 113
4 votes
1 answer
262 views

int256 range on geth command line

When I do the following on the geth command line: 20000000000000000000-19999999999999999989 it returns 0 I'm guessing this is because of a 64 bit limit on ints. Is there a way to get it to return ...
Lee's user avatar
  • 8,548
3 votes
3 answers
972 views

Get order of magnitude of an integer in solidity

What is a way of getting the order of magnitude of an integer (or float) in a solidity contract? e.g. such that MyContract.getOrderMag(2564) returns 3 MyContract.getOrderMag(987) returns 2 ...
Lee's user avatar
  • 8,548