It is currently Sat Apr 29, 2017 10:30 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Why are leading zeros such a problem on Android?
Unread postPosted: Mon Mar 27, 2017 2:56 pm 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 11
I was quite proud of myself when I managed to implement the BBP algorithm on an Android phone. I tested with a for/next loop going from -1 to 15. I was confused at first when I saw that interations 12 and 13 where giving the same answer until I realized that the leading zero on #12 wasn't getting printed. I thought the if/then/else structure was too finicky for a modern computer language, but trying to get print using$() is just kicking my ***. Here's the actual code i used (v is the output of the BBP algorithm, which I will soon publish when I tighten it up a little bit.)

PRINT USING$("", "%14X", INT(V))

Doesn't print the leading zero of the twelfth iteration. Fine, so i put in the "zero flag" thats supposed to after the '%'. Didn't make any difference; it doesn't the see the zero as a "leading zero flag". It sees it as part of the "14". How do I get around this as efficiently as possible?


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Mon Mar 27, 2017 11:25 pm 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1317
Hi ReNoob

Have you had a look at
FORMAT$(<pattern_sexp>, <nexp>)
Page 73 in manual; just a thought

Regards Roy


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Tue Mar 28, 2017 2:19 am 
Online

Joined: Tue Dec 04, 2012 10:50 am
Posts: 644
Location: UK
ReNoob wrote:
PRINT USING$("", "%14X", INT(V))

Yes, I agree with Roy. You seem to be programming in some other language than Basic!

Tell us what you think the elements of your format pattern will do for you. I cannot see anything in the manual about using digits in a pattern...

As for what your mention of if/then/else has to do with your case, there's no way of telling!

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Tue Mar 28, 2017 6:25 am 
Offline

Joined: Sat Feb 11, 2017 1:40 am
Posts: 68
Location: France
roy wrote:
Hi ReNoob

Have you had a look at
FORMAT$(<pattern_sexp>, <nexp>)
Page 73 in manual; just a thought

Regards Roy

In fact, you have no locale to apply (no decimal point, "%,x" not allowed). Then format$ does the job. But it is with a greater pattern than simply "%14x".
Besides that, why 14, the room for seven bytes?

_________________
Alain


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Tue Mar 28, 2017 7:53 am 
Offline

Joined: Sat Feb 11, 2017 1:40 am
Posts: 68
Location: France
ReNoob wrote:
Fine, so i put in the "zero flag" thats supposed /)to after the '%'. Didn't make any difference; it doesn't the see the zero as a "leading zero flag". It sees it as part of the "14". How do I get around this as efficiently as possible?

The correct syntax should be "%0,14X". As for "%0,14d".
But BASIC sucks when reaching the comma, here parsed as a flag, (though following 0) which is forbidden in x format...
The answer to your initial question seems to be: only difficult for hex numbers, because a weak in BASIC!'s parsing of using$.

_________________
Alain


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Tue Mar 28, 2017 10:01 am 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 11
Thank you to all for your responses! I should give a little background: I not new to programming in general, but this particular quagmire was my attempt to translate BBP from Python (which I'm not overly familiar with) to a dialect of BASIC that I'm also not familiar with. And believe me, typing it all on an Android could reduce better men than I to tears. I spent more time trying to get the cursor where I wanted it than I did actually thinking. That said, here's the work in progress:

Code:
fn.def Sf(j,n)
!Left Sum
Let s=0: k=0
while k<=n
    let r=8*k+j
    let y=16^(n-k++)
    let z=mod(y,r)
    let s=frac(s+(z/r))
repeat
!Right sum
let t=0: let k=n+1
do
   let y=16^(n-k)
   let z=j+8*k++
   let w=t+(y/z)
if t=w then D_U.break
t=w
Until (1=2)
fn.rtn(s+t)
fn.end

!start of main program
for x = -1 to 15
print using$("","%2d",int(x));": ";
let v = Sf(1,x)*4 -Sf(4,x)*2 -Sf(5,x) -Sf(6,x)
let v = v*pow(16,15)
let v =  shift(v,-4)
Print [Insert insane frustration here]
next x



Some quick notes: I used let a lot when it probably wasn't necessary because I just wanted to cover all my bases, so to speak. Likewise, I could've put many of these statements on the same line, but I wanted to have "break points" to pin down exactly where a problem was instead of parsing a multiple statement line for one typo.
But now we're at the interesting part. The only form of format$ or using$ I could get to render a leading zero actually prefaced everything with a zero! So I wussed out and did it the easy way.
I'd noticed that no matter what number I put in the format field it still printed 16 digits. So here's how I got my leading zero(s):

Code:
let g$ = hex$(int(V))
while len(g$)<>16
   g$="0"+g$
repeat
print g$


Cheating? I don't really think so. I'm going to be using it for a cryptology experiment, where a Mid$ statement will have to pick one digit out of the sixteen that get rendered at one time. So, I'd eventually have to make the output a string anyway.
Thank you for bearing with me!
Peace out, ReNoob


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Tue Mar 28, 2017 10:18 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 299
ReNoob wrote:
Code:
let g$ = hex$(int(V))
while len(g$)<>16
   g$="0"+g$
repeat
print g$




Code:
let g$ = hex$(int(V))
g$=RIGHT$("0000000000000000"+g$, 16)
print g$


Regards
Gregor


Report this post
Top
 Profile  
 
 Post subject: Re: Why are leading zeros such a problem on Android?
Unread postPosted: Tue Mar 28, 2017 11:09 am 
Offline
User avatar

Joined: Mon Mar 27, 2017 2:42 pm
Posts: 11
Thanks, Gregor! That's my kind of solution; quick, to the point, no unnecessary loops. Nice work!


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred