Browsing this Thread:
1 Anonymous Users
|
Re: 關於浮點數 儲存於EEPROM格式問題
|
|
版主
Joined
: 2004/4/30 10:53 最後登入時間
: 2021/11/30 18:11
From CAE, Microchip
Group:
站務管理者 註冊會員
Level : 75 HP : 744 / 1861 MP : 5367 / 108732 EXP : 45
|
如果是用 C 寫的話就很簡單了,如下範例 : 使用 union 與 struct 的資料架構來分解資料 union FPvar { float FPNum; //floating point access struct { unsigned char Arg0; //argument byte 0 access unsigned char Arg1; //argument byte 1 access unsigned char Arg2; //argument byte 2 access unsigned char Exp; //exponent byte access } ByByte; } Foo;
Foo.FPNum = 3.14159; // 設定一浮點數值 Exponent = Foo.ByByte.Exp - 0x7F; //取出指數部分 Argument_0 = Foo.ByByte.Arg0; // 取出第一個小數部分
發表於: 2004/8/26 17:37
|
|
|
關於浮點數 儲存於EEPROM格式問題
|
|
新會員
Joined
: 2004/8/26 16:01 最後登入時間
: 2015/10/12 22:49
Group:
註冊會員
Level : 1 HP : 0 / 8 MP : 1 / 490 EXP : 34
|
由於I2C的EEPROM 是以byte為單位傳輸資料 浮點數則是由 4個byte 所組成 如此該如何才能 將浮點數儲存於I2C的EEPROM 曾經想過將 浮點數分解成4個byte 但是不知該 如何分解與組合 感謝賜教
發表於: 2004/8/26 16:05
|
|
You can view topic.
你 不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.