プログラム開発: 2005年3月アーカイブ

前回は、修行が足りなかったみたい。
union なんて必要ありません。
メモリ上のデータの並びがわかります。
Intel だったらリトルエンディアン

#include
#include

typedef unsigned char BYTE;

using namespace std;

int main()
{
double d;
d = 1.0;
BYTE *b = reinterpret_cast(&d);

// ビッグエンディアン
for (int i = 0; i < sizeof(double); ++i)
cout << setw(2) << setfill('0') << hex << static_cast(*(b + i));

cout << endl;

// リトルエンディアン
for (int i = sizeof(double); i != 0; --i)
cout << setw(2) << setfill('0') << hex << static_cast(*(b + i));

cout << endl;

return 0;
}

プログラム開発: 月別アーカイブ

カテゴリ

ウェブページ

このアーカイブについて

このページには、2005年3月以降に書かれたブログ記事のうちプログラム開発カテゴリに属しているものが含まれています。

前のアーカイブはプログラム開発: 2005年1月です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。