본문 바로가기

전체 글195

[python] 연속된 8Bit Bytes 를 float 등의 타입으로 바꾸는 방법. Struct module 서로 다른 컴퓨터(언어, 시스템) 끼리 소켓통신을 할때 데이터 타입의 보존및 원활한 통신을 위해 1 byte array를 서로 주고 받으면서 통신한다. matlab 같은 경우는 typecast(data,'uint8') , typecast(data,'single') 이런식으로 ,c같은 경우엔 byte array를 원하는 변수타입에 넣기만 하면 알아서 casting되는 듯 한데Python은 어떻게 할까? 바로 struct 모듈을 이용한다. >>> import struct >>> struct.pack('f', 3.141592654) '\xdb\x0fI@' >>> struct.unpack('f', '\xdb\x0fI@') (3.1415927410125732,) >>> struct.pack('4f', 1.0, 2.. 2012. 6. 23.
The fundamental determinant of success Many people believe that success is primarily influenced by luck or skill.However this view of success is misguided. The truth is that perseverance is the ultimate factor that determins how successful a person will be in the end.People who follow through on what the set out to do will inevitably be successful.On the other hand, those who give up at the first hint of adversity tend to fall regard.. 2012. 5. 11.
리눅스 C 에서 파일 다루기 C나 C++ 언어 자체로 파일상태를 완전히 다 다룰순 없다. 기껏해야 fopen 정도.. linux자체내의 system call을 이용해야 하는데 몇가지 명령어 포스팅 한다. 헤더는 #include #include #include 1. 파일 또는 티렉토리의 상태 (exist or not or ....) stat 라는 system 함수를 사용한다. 사용법은 struct stat st; 로 객체만들고, int fl = stat("./renamed",&st) 이렇게 사용쓴다. 리턴값은 정상적으로 파일 또는 디렉토리의 정보를 얻으면 0, 에러나면 -1 자세한 에러 목록은 errno에 남는다. stat 구조체 항목은 struct stat { dev_t st_dev; /* ID of device containing.. 2012. 5. 3.
fopen 의 segmentation fault. 나는 컴퓨터과를 나오지 않다보니 프로그래밍하는데 기본이 없다. 사실 코딩을 하면서 자료구조를 왜 배워야하지? 그냥 코딩 하면 되잖아 라는 안일한 생각을 했는데 오늘 피봤다..... -_- FILE * fp; fp = fopen("a.txt","rb"); 를 하면 fp엔 파일이 존재할 경우엔 해당 파일 포인터가, 존재하지 않을땐 NULL이 들어간다. 그런데 fopen 그 자체에서 segmentation fault 가 뜨는 이유는 무엇인가 ㄷㄷ 구글링을 해보니 다양한 이유가 있었는데 나의 경우는 fopen이 아니라, OS자체의 Stack memory 를 넘어선 것이었다. (stack overflow 사이트를 그리 들락날락하면서 이런것을 몰랐다니-_-) tcshell 의 경우 limit 라는 명령은 보다 시피.. 2012. 5. 3.