用C語言將.JPEG轉換成2進制
winggundam :: all :: 電腦知識
第1頁(共1頁)
用C語言將.JPEG轉換成2進制
#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;
}
#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;
}
用C語言將.JPEG轉換成16進制
#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;
}
#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;
}
winggundam :: all :: 電腦知識
第1頁(共1頁)
這個論壇的權限:
您 無法 在這個版面回復文章