bitshift in matlab vs ishft in fortran
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I am trying to convert a large 64 bit number into 2x 32 bit numbers, Here is my code:
U = bitshift(v, -24);
L = bitand(v, 0x000000ffffffs64);
This is replicated off of fortran code:
U = ishft(v, -24)
L = iand(v, Z'000000ffffff')
For value v = 2830037, the L's agree, but "bitshift(2830037, -24) = 0" and "ishft(2830037, -24) = 1".
I am confused. Any help would be appreciated!
1 Kommentar
Shashi Kiran
am 16 Sep. 2024
Hi Jaden,
I see that U is zero when running the Fortran code(in onlinegdb compiler) as well. Are there any other ways to replicate the issue you are experiencing?
Antworten (1)
Steven Lord
am 16 Sep. 2024
Instead of using bit operations yourself, why not just use typecast?
t = 'int32';
x = randi([intmin(t), intmax(t)], 1, 2, t) % 2 random int32 values
y = typecast(x, 'int64')
z = typecast(y, t)
format hex
x
y
The swapbytes function may also be of interest to you.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!