Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add string operation for int256 in Strings.sol #3758

Closed
Suvadra-Barua opened this issue Oct 12, 2022 · 10 comments
Closed

Add string operation for int256 in Strings.sol #3758

Suvadra-Barua opened this issue Oct 12, 2022 · 10 comments
Labels
feature New contracts, functions, or helpers. good first issue Low hanging fruit for new contributors to get involved!

Comments

@Suvadra-Barua
Copy link

🧐 Motivation
There is no implementation of the conversion of int256 to String

📝 Details
Using Strings.sol , We can convert uint256 to String,HexString and address to HexString. But int256 to string is required in many cases.

@Amxx Amxx added feature New contracts, functions, or helpers. good first issue Low hanging fruit for new contributors to get involved! labels Oct 17, 2022
@ernestognw
Copy link
Member

Partially solved in #3773, although there's no toHexString implementation

@Amxx
Copy link
Collaborator

Amxx commented Jan 19, 2023

What would the Hex representation of a negative integer be? If you want the 2-complement representation, just hard-cast the int256 to a uint256 and then do toHexString(uint256)

@ernestognw
Copy link
Member

ernestognw commented Jan 20, 2023

What would the Hex representation of a negative integer be?

I'd say there would be multiple Hex representations available, but that should be an standard so hold on for now.

@Amxx
Copy link
Collaborator

Amxx commented Jan 20, 2023

I'd say there should not be multiple representations available in our libraries. Any user is free to chose one they like, and implement it on top of what we already have.

@ernestognw
Copy link
Member

ernestognw commented Jan 20, 2023

I completely agree with not supporting them all, but I don't know about any way of generalizing it, and there's no standard usage afaik

just hard-cast the int256 to a uint256 and then do toHexString(uint256)

This is the most general version I'd think about. Can be converted to 2's complement.

@Amxx
Copy link
Collaborator

Amxx commented Jan 20, 2023

I'd like to says that I've never seen anyone write -0xE8A1 ... but I'd be lying.

@ernestognw
Copy link
Member

Can you share a source (if any)? I haven't seen any two's complement on-chain, but maybe reaching out to people who's done it might be helpful

@Amxx
Copy link
Collaborator

Amxx commented Jan 24, 2023

I don't have any sources, because I have never seen anyone do int→string in solidity. Rather then go look for it, the potential users should come to us with realistic usecases.

When users ask for features, we ask them what their motivation/usecase is, and evaluate if that is relevant to the community in general.

@DigitalSubham
Copy link

I am working on this issue, please assign this to me

@Amxx
Copy link
Collaborator

Amxx commented Mar 2, 2023

@DigitalSubham

I'm not sure why this issue is not already closed, but we already have an implementation of toString(int256)

@Amxx Amxx closed this as completed Mar 2, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature New contracts, functions, or helpers. good first issue Low hanging fruit for new contributors to get involved!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants