Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 03:05 15 Nov 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 : Having a senior moment with 64bit to signed 32bit...

Author Message
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:59am 04 Oct 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10582
Posted: 11:03am 04 Oct 2020
Copy link to clipboard 
Print this post

if a% and &B80000000 then a% = a% OR &HFFFFFFFF00000000
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 11:23am 04 Oct 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10582
Posted: 11:24am 04 Oct 2020
Copy link to clipboard 
Print this post

Sorry typo should have been &H
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 12:03pm 04 Oct 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10582
Posted: 12:08pm 04 Oct 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 1646
Posted: 01:03pm 04 Oct 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 2171
Posted: 08:27pm 04 Oct 2020
Copy link to clipboard 
Print this post

Sign extend any "size" number

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

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 06:13am 06 Oct 2020
Copy link to clipboard 
Print this post

Good stuff....Thanks Cap'n
 
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