강제 캐스팅에 의한 1byte 단위 접근 방법
1Byte access 강제 캐스팅에 의한 1byte 단위 접근 방법
다음과 같이 출력되도록 코드를 짜시오. temp : 0x12345678 temp : 0x78563412 // 강제 캐스팅에 의한 1byte 접근법 #include <stdio.h> int main(){ char *s; char swap_char; int temp=0x12345678; s=(char*)&temp; //4byte의 값을 1byte씩 접근 // a=(char)&temp; 변수 자료형의 형변환 printf("temp : 0x%x\n",temp ); swap_char=*s; *s=*(s+3); *(s+3)=swap_char; swap_char=*(s+1); *(s+1)=*(s+2); *(s+2)=swap_char; printf("temp : 0x%x\n",temp ); } 이런 방법론은 Endian 문제에 적용시킬수 있다. Little Endian 과 Big Endian 과의 데이터 불일치가