×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# convert AScii string to 64 bit integer

## convert AScii string to 64 bit integer

(OP)
Hi,
I am to take an input from user. Then, I need to convert that Ascii string to a 64-bit integer. I can do this with 32-bit, but I have no idea how to do it in 64-bit.

Anybody know, please give me a hint. Thanks a lot.
Replies continue below

### RE: convert AScii string to 64 bit integer

First you need to know how to perform multi-word addition and subtraction, as well as multi-word shifts.

This is done using the adc and sbb instructions.  For shifts you must use rcl and rcr.

Basically, to add two 64-bit numbers:
.data
num1 dq 100
num2 dq 200
.code
mov ecx,dword ptr num1
mov ecx,dword ptr num1[4]

Subtraction is performed by replacing ADD with SUB and ADC with SBB.

For shift, you must shift by only one bit at a time.
To shift a 64-bit number left (i.e. x2)
shl dword ptr num1,1
rcl dword ptr num1[4],1

To shift a 64-bit number right (i.e. /2)
shr dword ptr num1[4],1
rcr dword ptr num1,1

So why do you need to know about addition and shifting?  Because you CAN'T use the 32-bit mul and div reliably!  Remember you are using 64-bit numbers and mul and div can't hack 64-bit numbers.

So how to multiply by 10 (which is needed to convert to integer, right?)??

Well, multiply by 10 is:
10X
2(5X)
2(4X + 1X)

So you need to multiply by powers of two.  And how to multiply by powers of two?  Why shift, of course!!!

So, to multiply by 10, put the number in two registers, shift the registers left twice, add the original number, then shift the registers again.

Have fun!  And make sure you check your numbers...

"Information has a tendency to be free.  Which means someone will always tell you something you don't want to know."

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!