- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I have 2 byte positive integers which I need to write, as 1 byte unsigned integers, to a binary file.
The binary file is opened as big endian.
Is there a simple way to do this?
Thanks, Andy
The binary file is opened as big endian.
Is there a simple way to do this?
Thanks, Andy
링크가 복사됨
4 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I don't understand what you want to do. Can you provide examples with, perhaps, hex strings or bit patterns explaining what you want to go where? Big-endian has no meaning for one-byte values.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I want to write integers ranging from 0 (as hex 00) through 255 (as FF).
(I wanted to make clear that big endian was in play in case that might affect the strategy.)
With signed integers I must use 2 bytes to get the 0 to 255 range. If I write the following array I get 16 binary bytes. I need to write it as 8 bytes. Integer(1) doesn't let me count to 255.
integer(2) IQ_2B(2,4)
write(fileID) IQ_2B(1,:), IQ_2B(2,:)
I thought writing one integer at a time might simplify the problem, thus my One Byte question.
Looks like an easy work around is to add
integer(1) IQ_1B(2,4)
! copy:
IQ_1B = IQ_2B
! and
write(fileID) IQ_1B(1,:), IQ_1B(2,:) ! instead of writing IQ_2B
! letting the signed integer hex representation do the job for me.
(I wanted to make clear that big endian was in play in case that might affect the strategy.)
With signed integers I must use 2 bytes to get the 0 to 255 range. If I write the following array I get 16 binary bytes. I need to write it as 8 bytes. Integer(1) doesn't let me count to 255.
integer(2) IQ_2B(2,4)
write(fileID) IQ_2B(1,:), IQ_2B(2,:)
I thought writing one integer at a time might simplify the problem, thus my One Byte question.
Looks like an easy work around is to add
integer(1) IQ_1B(2,4)
! copy:
IQ_1B = IQ_2B
! and
write(fileID) IQ_1B(1,:), IQ_1B(2,:) ! instead of writing IQ_2B
! letting the signed integer hex representation do the job for me.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
How about:
write (fileID) INT(IQ_2B(1:),1), INT(IQ_2B(2,:),1)
Since our compiler does not offer integer overflow detection, there should be no problem using values in the "unsigned range".
write (fileID) INT(IQ_2B(1:),1), INT(IQ_2B(2,:),1)
Since our compiler does not offer integer overflow detection, there should be no problem using values in the "unsigned range".