From 2f81eea6b6999e2480d42f8bde77a46b3c4b80e8 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Sat, 18 Jun 2022 09:05:37 -0400 Subject: [PATCH] update `hex_string` (#68) Co-authored-by: mecej4 <68881733+xecej4@users.noreply.github.com> --- perf.f90 | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/perf.f90 b/perf.f90 index a0af4d6..054dc61 100644 --- a/perf.f90 +++ b/perf.f90 @@ -148,36 +148,25 @@ end function sysclock2ms subroutine hex_string(dec,hexchar) integer, intent(in) :: dec character(*) :: hexchar - character(len(hexchar)) :: tempchar integer :: i - integer :: quotient, remainder + integer :: quotient character(len=1), parameter :: table(0:15) = & [(char(i),i=ichar('0'),ichar('9')),(char(i),i=ichar('A'),ichar('F'))] quotient = dec - - hexchar(:) = ' ' - tempchar(:) = ' ' - i = 1 - do while (quotient /= 0 .and. i <= len(hexchar)) + hexchar = '00000000' - remainder = modulo(quotient,16) + i = 8 + do while (quotient /= 0 .and. i > 0) - tempchar(i:i) = table(remainder) - i = i+1 + hexchar(i:i) = table(iand(quotient,15)) + i = i-1 - quotient = quotient/16 - - end do - - do i=1,len_trim(tempchar) - - hexchar(i:i) = tempchar(len_trim(tempchar)-i+1:len_trim(tempchar)-i+1) - - end do + quotient = ishft(quotient,-4) +end do end subroutine hex_string