PDA

View Full Version : 'DIG' equivalent in other Languages?



Art
- 27th November 2005, 05:02
Hi Guys,
Just wondering if there's a way to do it in C or LUA, or any other language
for that matter.
Forgive me if it is off topic getting into another platform but the problem
is I am trying to convert BASIC code that uses this operator.

Now I have a number that is limited to three digits (max '999'),
and need to load each digit into seperate variables so they
can each be printed as seperate numbers that each range from 0 to 9.

Would the compiler divide it all down and throw away the remainders?
It seems a bit time consuming of the pic to do it that way.
Cheers, Art.

Bruce
- 27th November 2005, 07:51
DIG just divides the number by 10 and returns the remainder.

Example. Say you want to extract digits 0, 1, and 2 from 102.

102/10 = 10.2 <-- DIG 0 = 2
10/10 = 1.0 <-- DIG 1 = 0
1/10 = 0.1 <-- DIG 2 = 1

Pretty simple stuff to do with any language.

Art
- 27th November 2005, 22:43
hehe..
It wasn't easy for pic basic to do it in asm

but you are right, and I was making it a bigger problem than it is :D
I think the language I'm using can have decimal numbers placed in variables.
Art.