![]() |
Forum Index : Microcontroller and PC projects : 32bit to 64bit
Author | Message | ||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
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 KingdomPosts: 10310 |
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 KingdomPosts: 1646 |
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 KingdomPosts: 2170 |
http://www.fruitoftheshed.com/MMBasic.Sign-Extend-an-Integer.ashx |
||||
Tinine Guru ![]() Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
![]() 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 KingdomPosts: 1646 |
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 KingdomPosts: 2170 |
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 KingdomPosts: 1646 |
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 ![]() 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 KingdomPosts: 2170 |
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: CanadaPosts: 1132 |
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 KingdomPosts: 1646 |
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 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |