Comments (11)
Hello @zackshapiro,
That method would work for a lot of the logic, but once you get to multiplication it would get harder. I do have the double width operations defined, so you could just depend on this project and wrap around those operations to get what you want; assuming that you don’t want to be able to perform double width 256-bit arithmetic.
from uint128.
Thanks for getting back to me so fast! I don't need to do any arithmetic, I just need to represent numbers in UInt128 and public/private key pairs as UInt256
from uint128.
Oh, then you could probably just compose a struct from this struct having an upper and lower value like mine.
Are you wanting to store as 256bit numbers and present as a string?
BTW; my double width operations didn’t do what I thought, so it would take a bit of work to make a similar 256bit library.
from uint128.
Are you wanting to store as 256bit numbers and present as a string?
Yeah, exactly. In my project I need to have a 256 bit seed, run it through a hashing algorithm to get a key pair and then do another hashing operation with the public key. Eventually I'll need to do a string operation on one of them but that's all I'm using them for
from uint128.
You’d probably want to create a new struct, using a higher and lower value of 128 bit UInts and include your hashing algorithm as a method.
Take a look at my string methods when you’re ready to represent the numbers as strings, as I believe my method will work on any sized integer count. You might need to introduce your own bit shifting methods as well, as I don’t recall off the top of my head what my string method relies on.
from uint128.
Got it. Thanks @Jitsusama.
I've never worked at the bit level before so I'm a bit intimidated by all this but I'll figure it out.
Working on the struct now
from uint128.
_valueToString is the method for my String conversion.
It will require a division method instead of a bit shift, but that probably depends on a bit shift method. I’d have to dig to remember.
It can be a bit hairy. I started writing this library when I wanted to natively store IPv6 addresses. I soon found myself down a rabbit hole 😀
from uint128.
@Jitsusama Here's my implementation,
https://gist.github.com/zackshapiro/848a2c1efeda9a34b89b8b5648a7c24c
I took all of the UInt128s and turned them into UInt256s, all the 64s and doubled them, all the 127s and replaced them with 255s
Would you mind taking a look and seeing how that looks since you're much more familiar with the implementation? I'm still digesting :)
I left 2 comments at the bottom of my gist with open questions, if I needed to do anything more in two spots.
The multipliedFullWidth
is a doozy of a method, but sounds like I may be able to cut it - in needed - since it doesn't fit my project's needs
from uint128.
The multipliedFillWidth method will need significant changes in order to handle 256 bits of math. It’s basically performing long multiplication as you might do on paper, but instead of handling each decimal digit, it’s doing it in chunks of digits. I don’t have my MacBook with me (I’m on a business trip), so I can’t play much, but I would strongly recommend writing out some XCTestCases for scenarios you need to be able to handle and then use breakpoints to start figuring out where things break down. Unfortunately there is a lot of interdependency on arithmetic methods to perform tasks as the only way to do more “advanced” arithmetic is by composing simpler arithmetic, which all has to be handled by your library.
from uint128.
Got it working!
Thanks for your help Joel
from uint128.
That’s great to hear, and you are most welcome!
from uint128.
Related Issues (17)
- Needs Test Cases HOT 7
- swift 3.0 HOT 4
- Please consider Carthage support HOT 1
- Xcode 9.0 beta build error HOT 21
- No build scheme for iOS platform HOT 4
- can't find Instance method 'fromUnparsedString' in swift3.2 branch HOT 7
- Not correct work: significantBits HOT 5
- ArithmeticOverflow has been deleted HOT 2
- Cocoapods support HOT 8
- Bump Version Number to 0.9.0
- Add UInt128.max HOT 2
- UInt128 to String conversions are slow HOT 3
- Unable to add with package manager HOT 2
- Is UInt128 Ready for a Version Bump? HOT 4
- Convert value to CVarArg type HOT 1
- does not work with code 15 out of the box. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uint128.