現在VBAを用いて、他アプリケーションで使う以下の様な処理を組んでいるのですが
//-----------------------------------------//
セルの入っているデータを
1-1)整数データ
1-2)実数データ
1-3)文字列データ
エンディアンを変換してバイナリでファイル出力するという
//-----------------------------------------//
1-2)の実数データの出力がうまくいきません。
Single型のデータをどう出力してもうまくいきません。
1-1)には
//1byte------------------------------------//
Public Function write_byte(off As Long, data As Integer)
Dim bytedata As Byte
If data < 0 Then
bytedata = 255 - (data + 1)
Else
bytedata = data
End If
Put FileNum, off, bytedata
off = off + 1
End Function
//2byte------------------------------------//
Public Function write_short(off As Long, data As Integer)
Put FileNum, off, data
off = off + 2
End Function
//4byte-----------------------------------//
Public Function write_int(off As Long, data As Long)
Put FileNum, off, data
off = off + 4
End Function
//2byte endian-----------------------------//
Function ChangeEndianInt(Value As Integer) As Integer
Dim hi As Byte
Dim lo As Byte
hi = (Value And &HFF00&) \ &H100&
lo = Value And &HFF&
ChangeEndianInt = CastInt(lo * &H100&) Or (hi And &HFF&)
End Function
//4byte endian-----------------------------//
Function ChangeEndianLong(Value As Long) As Long
Dim hi As Integer
Dim lo As Integer
hi = (Value And &HFFFF0000) \ &H10000
lo = CastInt(Value And &HFFFF&)
ChangeEndianLong = _
(ChangeEndianInt(lo) * &H10000) Or (ChangeEndianInt(hi) And &HFFFF&)
End Function
//long → int------------------------------//
Function CastInt(Value As Long) As Integer
Dim val As Long
val = Value And &HFFFF&
If val And &H8000& Then
CastInt = CInt(val And &H7FFF)
CastInt = CastInt Or &H8000
Else
CastInt = CInt(val)
End If
End Function
//---------------------------------------//
を使用しています。
上記のような形で同じく実数を処理するには、どういう処理を
行えばいいのか、お知恵をお貸しいただければと思います。
要領を得ない質問の仕方で申し訳ないのですが
宜しくお願い致します。
要領えない回答ですみません、よく理解してないもので
「実数 16進数」あたりで検索するとか?