Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:11 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : 32bit to 64bit

Author Message
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 05:49pm 07 Sep 2022
Copy link to clipboard 
Print this post

I have a 32bit counter that I will assign to MMBasic's 64bit integer.

When I hit rollover, I want the 64bit to keep counting in whatever direction.

I can think of ways to do this but I suspect that whatever I come up with will be clunky  

What's the niftiest way of doing this?


Craig
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 06:08pm 07 Sep 2022
Copy link to clipboard 
Print this post

Does this do what you want ?


if new32<the64 mod &HFFFFFFFF then 'counter has rolled over
   inc the64, &H100000000+new64
else 'just replace the bottom 32 bits
   the64 = (the64 and &HFFFFFFFF00000000) + new32
endif
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:28pm 07 Sep 2022
Copy link to clipboard 
Print this post

Ah-ha, I was actually on the right track but there's a bit there that you showed me in the past.

Will have a play

Many, many thanks, Pete  
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 07:34pm 07 Sep 2022
Copy link to clipboard 
Print this post

http://www.fruitoftheshed.com/MMBasic.Sign-Extend-an-Integer.ashx
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:01pm 07 Sep 2022
Copy link to clipboard 
Print this post



Honestly....as I was typing the OP, I was thinking...it's gonna be Pete or Cap'n



Just fell out of the attic, retrieving a bunch of 3.5" floppies...don't ask  


Craig
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 05:34am 08 Sep 2022
Copy link to clipboard 
Print this post

  CaptainBoing said  http://www.fruitoftheshed.com/MMBasic.Sign-Extend-an-Integer.ashx


Morning, Cap'n  

OK, just got to my desk with first coffee of the morning.
At first glance, I will need to expand upon this, right?

I mean; if my counter is running in the positive direction, bit31 is going to be flipping hi/lo multiple times but I want my 64bit integer to keep counting positive.

Naturally, it also needs to work for the other direction.

Craig
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 06:45am 08 Sep 2022
Copy link to clipboard 
Print this post

Sorry Craig, so the 64 bit counter needs to go up regardless of the direction of the 32 bit?

e.g.
counter32 increments 10 steps: counter64 bit increments 10 steps,
counter32 decrements 10 steps: counter64 bit increments 10 steps ?

in which case ignore my post, I thought (from my brief scan) that you wanted to convert a signed 32 bit to a signed 64bit.

that function I posted just extends all zeros or all ones from a certain point to bit 63

I blame old age and drink...
Edited 2022-09-08 16:47 by CaptainBoing
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:07am 08 Sep 2022
Copy link to clipboard 
Print this post

  CaptainBoing said  Sorry Craig, so the 64 bit counter needs to go up regardless of the direction of the 32 bit?

e.g.
counter32 increments 10 steps: counter64 bit increments 10 steps,
counter32 decrements 10 steps: counter64 bit increments 10 steps ?

in which case ignore my post, I thought (from my brief scan) that you wanted to convert a signed 32 bit to a signed 64bit.

that function I posted just extends all zeros or all ones from a certain point to bit 63

I blame old age and drink...


Yeah, for example, there are devices with 8 or 16 bit physical counters but from a coding standpoint we have a 32 bit counter. I can see how to do this but we share an obsession for efficiency   and so I want the leanest solution.

I'll post what I come-up with, based on the sort of thing that Pete posted and see if you guys can trim it  

Craig
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 07:30am 08 Sep 2022
Copy link to clipboard 
Print this post

  Tinine said   we share an obsession for efficiency   and so I want the leanest solution.


totally get that. years of 80s (and 90s a bit) assembler programming taught me to keep my room tidy
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 03:53pm 08 Sep 2022
Copy link to clipboard 
Print this post

Are you just hosting a 32 bit up-down counter in a 64 bit variable? If you are not doing any signed math, you don't need to do anything - it just works.
Visit Vegipete's *Mite Library for cool programs.
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 05:08pm 08 Sep 2022
Copy link to clipboard 
Print this post

  vegipete said  Are you just hosting a 32 bit up-down counter in a 64 bit variable? If you are not doing any signed math, you don't need to do anything - it just works.


This is what I've been telling myself  

I mean, the 32bits are unaware that 64bits exist and so they don't do anything different, right?  


You guys just wanna see me suffer  

Is it obvious that I didn't do too well in school?

Craig
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025