用C語言將.JPEG轉換成2進制

上一篇主題 下一篇主題 向下

用C語言將.JPEG轉換成2進制

發表 由 Admin 于 周三 五月 05, 2010 2:31 pm

#include <stdio.h>
#include <stdlib.h>

int main (){
FILE * file;

//open in bin form
file = fopen ("myfile.txt","rb");
int i;
char *buffer;
unsigned long len;

if (file!=NULL){
fseek(file, 0, SEEK_END);
len=ftell(file);
fseek(file, 0, SEEK_SET);
buffer=(char *)malloc(len+1);

//store in buffer as char
fread(buffer, len, 1, file);

//print in Dec ASCII code form
for (i=0;i<len;i++)
printf("%d", (int) (((char *)buffer)));

}

fclose(file);

system("pause");
return 0;
}

Admin
Admin

文章數 : 15019
注冊日期 : 2009-07-11

檢視會員個人資料 http://winggundam.show5forum.com

回頂端 向下

用C語言將.JPEG轉換成16進制

發表 由 Admin 于 周四 五月 06, 2010 4:56 pm

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (){
FILE * file;

char ascii[4];
//open in bin form
file = fopen ("myfile.txt","rb");
int i,j;
char *buffer;
unsigned long len;
int num;

if (file!=NULL){
fseek(file, 0, SEEK_END);
len=ftell(file);
fseek(file, 0, SEEK_SET);
buffer=(char *)malloc(len);

//store in buffer as char
fread(buffer, len, 1, file);

//print in Dec ASCII code form
for (i=0;i<len;i++){

//先用integer 儲存 ASCII value
num = (int) ((char *)buffer);
printf("ASCII integer = %d ", num);

//用char array 儲存 16進制數值
//itoa 係integer 轉換 string function 16係表示 轉換16進制數值
itoa(num, ascii, 16);
printf("ASCII code = %s ", ascii);
printf("\n");

}

}

fclose(file);

system("pause");
return 0;
}

Admin
Admin

文章數 : 15019
注冊日期 : 2009-07-11

檢視會員個人資料 http://winggundam.show5forum.com

回頂端 向下

上一篇主題 下一篇主題 回頂端


 
這個論壇的權限:
無法 在這個版面回復文章