Can you help to convert this Fortran code to Matlab?
integer,parameter::k=selected_int_kind(18)
integer(k) v
integer U,L
111 READ(*,*) v
U = ishft(v, -24)
L = iand(v, Z'000000ffffff')
print*,L,U
! getting v back
v = int(L,k) + ishft(int(U,k),24)
print*,v
goto 111
end
We discussed this code a year ago, see https://forums.silverfrost.com/Forum/Topic/4344.
This code reads from screen 64bit number v you put from the keyboard and splits it into two 32bit single precision numbers U and L. Then it combines two numbers into v back to check if all went OK.
This code takes only first 24bits of the v number to restrict U and L to values below approximately 20 million, because if you convert more and then assign these U and L integer numbers to real single precision 32bit numbers (and we have to do that), all further bits will be lost (mantissa of real number is just 24 bits or so). This code with this tricky way can split v numbers up to 10^15 instead of just 20 million or so