64-bit and 128 bit integer as a combination of 32-bits

X

xyz

Hi all,

How to program 64-bit and 128-bit integers as a combination of 32bits.
I need this string to integer conversion.

Thank you
 
M

Malcolm McLean

How to program 64-bit and 128-bit integers as a combination of 32bits.
I need this string to integer conversion.
It's easiest in assembler. Instruction sets for 32-bit microprocessors
have the ability to access the carry when two numbers are added, or to
take the high 32 bits from a multiplication. It's more difficult to
achieve this in C. The easiest way to to declare an array of unsigned
shorts and treat the 64 or 128 bit number as a series of base 65536
digits. Then ypu use the algorithms you learnt at primary school to do
the four operations.
Binary to string and back can then be built on top of modulus ten,
multiply and divide.
 
R

robertwessel2

It's easiest in assembler. Instruction sets for 32-bit microprocessors
have the ability to access the carry when two numbers are added, or to
take the high 32 bits from a multiplication.


While OT, that's only true for some ISAs. Many RISCs do not have a
carry flag (or any flags at all), or an add-with-carry instruction,
and while you can generate a carry with a comparison*, it's clumsy at
best. And S/360 and its descendents didn't have a decent add-with
carry instruction until about a decade ago, and has a very non-
traditional carry indication anyway.


*if (a+b) .lt. a then carry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top