|
Forum Index : Microcontroller and PC projects : Having a senior moment with 64bit to signed 32bit...
| Author | Message | ||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
I am reading a signed 32bit counter into a MMBASIC integer which is 64bit What would be the most efficient method to derive the signed 32bit value? I just know it's going to be ridiculously simple |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10582 |
if a% and &B80000000 then a% = a% OR &HFFFFFFFF00000000 |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Whoa...I did a double-take on the &B8....Here's me thinking I'd RTFM Many thanks, Pete |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10582 |
Sorry typo should have been &H |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
That's a relief...I found &B under "64-bit Unsigned Integers" in the manual and I still felt like a dumb-a$$ |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10582 |
You could use &B but it needs a lot of 0s if a% and &B10000000000000000000000000000000 then a%=a% OR &B1111111111111111111111111111111100000000000000000000000000000000 |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
I was performing a compare & subtraction on the decimal value but bit-masking just feels more computer-ish |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
Sign extend any "size" number http://www.fruitoftheshed.com/MMBasic.Sign-Extend-an-Integer.ashx |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Good stuff....Thanks Cap'n |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |