Hi guys..

I have a question..

If i have 24 in AL, can i retrieve only the 2 ???

At this point you're not working with multiple bytes, so the only way to split up the value is to shift away the least significant digit.

Shifting only works for powers of two. In any case, it is a substitute for what is actually happening: you are dividing by the radix.

So, to get the tens place from a decimal number, you must first divide by ten, then get the remainder of another division by ten. For example:

4321
4321 divide 10 --> 432
432 modulo 10 --> 2

To get the hundreds place, you divide by ten twice (which is the same as dividing by 100). Etc.

Typical integer to string conversion routines use exactly this algorithm to get each digit, repeating until the number is zero.


It will be the same no matter how many bytes you use, since base 10 doesn't directly map to base 2; that is, a base 10 digit may span from one byte to another.

Hope this helps.

>Shifting only works for powers of two.
By "shifting" I meant knocking off the least significant digit (division by 10, for example), not bitwise shifting specifically. Sorry for the confusion.

> By "shifting" I meant knocking off the least significant digit...
Yeah, I figured that's what you meant, but a total newbie would have confused it. Natural language is an enemy, alas. (I know it; I confuse people often enough when I try to make a short answer. And no one reads a long answer through...) :sweat: ;)

So im suppose to divide the al register by 10 to get 2 in it ? means i have to store it somewhere first so that i can div again to get the scond char? i shall try and post back later !

Each time you divide you loose the least-significant digit (the one in the ones position).

So if you want to get the tens position digit (2 in both our examples) you divide by 10 to move it to the ones position. Then use modulo 10 to extract the ones digit only.

This is pure math, so you'll have to think about it some. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.