E
elliotng.ee
I have a text file that contains a header 32-bit binary. For example,
the text file could be:
%%This is the input text
%%test.txt
Date: Tue Dec 26 14:03:35 2006
00000000000000001111111111111111
11111111111111111111111111111111
00000000000000000000000000000000
11111111111111110000000000000000
I want to be able to take the 32-bit binary and convert it into
hexadecimal. The hexadecimal equivalent of the 32-bit binary string
will be utilized in another function. For example, when the code
reaches the first 32-bit binary string, it will send 0xFFFF to another
function. For the second 32-bit binary string, it will send 0xFFFFFFFF
to another function. The hexadecimal equivalent cannot be a string
since the function will need to be the exact hexadecimal number
(0xFFFF, 0xFFFFFFFF, etc.)
This is what I have so far:
#include <stdio.h>
int main(){
char c[33];
FILE *file;
file = fopen("test.txt", "r");
if (file == NULL){
printf("Error: File does not exist!\n");
return 1;
}
else{
while (fgets(c, 33, file) != NULL) {
if (((c[0]== '0') || (c[0]=='1')) && ((c[1] == '0') ||(c[1] == '1'))
&& ((c[2] == '0') || (c[2]=='1'))){
// Hexadecimal conversion occurs here
// Send the hexadecimal convertion to another function
}
}
fclose(file);
return 0;
}
}
How do I convert 32-bit binary string into hexadecimal?
the text file could be:
%%This is the input text
%%test.txt
Date: Tue Dec 26 14:03:35 2006
00000000000000001111111111111111
11111111111111111111111111111111
00000000000000000000000000000000
11111111111111110000000000000000
I want to be able to take the 32-bit binary and convert it into
hexadecimal. The hexadecimal equivalent of the 32-bit binary string
will be utilized in another function. For example, when the code
reaches the first 32-bit binary string, it will send 0xFFFF to another
function. For the second 32-bit binary string, it will send 0xFFFFFFFF
to another function. The hexadecimal equivalent cannot be a string
since the function will need to be the exact hexadecimal number
(0xFFFF, 0xFFFFFFFF, etc.)
This is what I have so far:
#include <stdio.h>
int main(){
char c[33];
FILE *file;
file = fopen("test.txt", "r");
if (file == NULL){
printf("Error: File does not exist!\n");
return 1;
}
else{
while (fgets(c, 33, file) != NULL) {
if (((c[0]== '0') || (c[0]=='1')) && ((c[1] == '0') ||(c[1] == '1'))
&& ((c[2] == '0') || (c[2]=='1'))){
// Hexadecimal conversion occurs here
// Send the hexadecimal convertion to another function
}
}
fclose(file);
return 0;
}
}
How do I convert 32-bit binary string into hexadecimal?