Jump to content

Extracting digits out of integers


shawn3090

Recommended Posts

Does anyone have an algotrithm to extract digits out of a number? I have thought for a long time about this to no avail. For example:

  • the 3 out of 1545253553
  • the 4th digit from the left of 011001011

 

I will be mainly using this for binary.

animsig.gif

[hide=Stats]I_B_Trolin_U.png[/hide]

"One death is a tragedy. A million deaths is a statistic."

-Joseph Stalin

Link to comment
Share on other sites

Well like Markup said it really depends on the language.

 

Most languages have a wide variety of string functions that you could utilize.

 

Are you looking to convert a decimal number to binary?

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Link to comment
Share on other sites

I am trying to make a binary to decimal converter on the ti-84 plus silver. I have the OS 2.53 with new shortcuts and stuff. I already made a d-b converter which was ridiculously easy.

animsig.gif

[hide=Stats]I_B_Trolin_U.png[/hide]

"One death is a tragedy. A million deaths is a statistic."

-Joseph Stalin

Link to comment
Share on other sites

Various methods, the easiest of which is to locate and use the built in d-b b-d b-h b-o ect functions.

If you wish to take on the challenge then assembly is the ideal method but I take it you are using BASIC or similar. In which case you could use a custom list as an alternative to an array and store each "binary bit" as an entry then perform simple logic to convert to decimal

Link to comment
Share on other sites

Use iPart(x) to retrieve the integer part of x.

If you let x = {4.5, pi, or 2}, iPart(x) will return {4, 3, or 2}.

 

Use fPart(x) to retreive the fractional part of x.

If you let x = {4.5, pi, or 2}, fPart(x) will return {0.5, pi-3, or 0}.

 

 

To call a digit from a specific place in a number, use iPart(10*fPart(x*10^(n-1))), where x is your number, and n is the number of digits behind the decimal point the number you are calling is located.

iPart(10*fPart(1.23456789*10^7))) will return the 8th ((7+1)th) number to the right of the decimal point, which is 9.

 

Oh, I guess you would probably be using this to call numbers from the left side of the decimal point. in that case..

iPart(10*fPart(1234.56789*10^(-n))) will return the nth number to the left of the decimal point.

 

There's probably a better code but I just threw that together from my other code, as you can probably guess.

 

It's probably best to stick with Dec->Bin functions already in the calculator (Not sure where to find 'em on the 84), but if you wanted to do it this way, these functions would be how you would do it.

Edited by Peregrine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.