- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm writing a hashing function using unsigned 32 bit integers, however I'm not sure if it can be written/printed? Haven't seen any documentation
What's the best method to write/print a c_int32_t integer in fortran ? In C printf would use PRIu32
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would say: copy the bits into a 64-bits integer and print that. I have not tested it but try:
i64 = transfer( [0, unsigned_int32], i64 )
(or the other way around?) Or use the bit manipulation routines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In Intel Fortran, you could use ZEXT(val,C_INT64_T). That is an extension, though widely implemented. In standard Fortran Arjen's suggestion is clever and workable. Unfortunately the various bit intrinsics, such as IBITS, don't allow changing the kind of the result. You could do something like IAND(INT(val,C_INT64_T),Z'00000000FFFFFFFF'), but that looks awkward.
Example:
use ISO_C_BINDING integer(4) val val = -214748364 print ('(Z8.8)'), IAND(INT(val,C_INT64_T),Z'00000000FFFFFFFF') end
D:\Projects>ifort /stand t.f90 Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.2.185 Build 20180210 Copyright (C) 1985-2018 Intel Corporation. All rights reserved. Microsoft (R) Incremental Linker Version 14.13.26129.0 Copyright (C) Microsoft Corporation. All rights reserved. -out:t.exe -subsystem:console t.obj D:\Projects>t.exe F3333334
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had thought of transfer but ZEXT works and is neater, thanks

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page