What's the best method for returning an unsigned long from a vector of ints? I'm working on a BigInt class in c++ and I'm storing the large numbers in a vector. I want to write a method that will return this vector as a standard long, provided it isn't larger than unsigned long can hold. Thanks
Return an unsigned long from vector of ints c++
744 Views Asked by mike At
1
There are 1 best solutions below
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in VECTOR
- C++ using std::vector across boundaries
- Mayavi - color vectors based on direction instead of magnitude
- Concatenate numbers in a vector to form one number
- C++ 2D vector - Convert int to double
- Downcast from a container of Base* to Derived* without explicit conversion
- Assigning values in a vector in non-sequential order
- Is it possible to find an element in a Vec<T> and remove it?
- Vector of Vector of object
- How to detect null values in a vector
- MatLab 3-vector plot/mesh with colour-scale
- How to create spaces in a textbox?
- libc++ difference between vector::insert overloads
- Make a character vector a numeric vector in R?
- Spacing errors while printing vector to JTextArea
- How to factor a vector (times it by itself a set number of times)?
Related Questions in UNSIGNED
- How to assign string to unsigned char[] in c++
- Is this an unavoidable signed and unsigned integer comparison?
- How the type of the result is decided based on type of operand?
- How to Add signed 8-bit from unsigned 16-bit?
- Argument of type "unsigned long *" is incompatible with parameter of type "HCRYPTHASH *"
- signed apk is not working but unsigned apk is working for G+ and FB integration
- Signed vs Unsigned comparison
- Arithmetic with unsigned variables in C
- Passing from string to unsigned short
- Conversion to "USHORT" from 'int' may alter its value
- What will happen if I assign negative value to an unsigned char?
- How does in assembly does assigning negative number to an unsigned int work?
- Converting a number to an UnsignedByte in PHP
- warning C4146 minus operator on unsigned type
- How to convert an IP address from NSString to unsigned int in Objective-C?
Related Questions in BIGINT
- Perl and Big Number
- BigInteger implementation, carry discrepancy
- Big Int implementation, how to handle leading zeros?
- Exception:Value was either too large or too small for an Int32 in asp.net?
- generate unique big integer for a tables column Laravel
- Date difference in Hours format from bigint in SQL Server
- Big JavaScript ints won't cast to String without rounding
- SystemC with c++ - how to print a sc_bigint variable?
- MySQL Automatically Calculate IBAN bigint overflow
- Return an unsigned long from vector of ints c++
- PHP int value is dependent on system
- Converting varchar to bigint in T-SQL
- How can I convert MySQL date stored as negative (signed) bigint to date format?
- C# - Class that uses ILists to store huge integers without BigInt. Can't figure out how to use CompareTo and Int.TryParse to +, -, and * two Lists
- Is there a BigInt large number class in the standard library?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Something along these lines, assuming the ints are stored in the vector with the least significant first:
Notes:
1) In practice you could save some bother because the number of loops is going to be either 1 or 2 on any vaguely normal-looking C++ implementation. So you could just write a case where you return
the_ints[0]and a case where you returnthe_ints[0] + (the_ints[1] << bits_in_int).2) I've been lazy. Because
intis signed andunsigned longis unsigned, you can actually fit at least oneintplus the least significant bit of anotherintinto anunsigned long. For example you might findbits_in_intis 31 butbits_in_longis 32.So actually in the "failed" case there is one last hope for peace, which is that (a) there is only one
intleft to process, and (b) its value fits in the remaining bits of the result. But like I say, I'm lazy, and I think I've shown the components you need to put together.For this reason if no other, you should probably use a vector of
unsigned intfor your BigInt. It's not required that the width ofunsigned longis a multiple of the number of bits inunsigned int, but it might be strange enough that you can ignore it.Update for base 10 digits, stored most significant first: