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.

>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.

Is C similar to C# (C-sharp); or are they completely different ? I was wondering if I should begin learning C# and the transition to C will be a tad ...

Write a program that displays all numbers divisible by 3 and 4 within a range entered by user. Display five numbers per line. Numbers are separated by exactly two spaces. ...

Hi guys. I am trying to create a program where the user inputs an integer and the program will cout the nth prime number. Unfortunatly when I try to cout ...