commit 90267e3dfff1d42f14e475ccc0c8da2d7830b46a Author: Theo BERNARD Date: Thu Dec 16 09:12:05 2021 +0000 code TO diff --git a/instrutobin.c b/instrutobin.c new file mode 100644 index 0000000..9a23f4e --- /dev/null +++ b/instrutobin.c @@ -0,0 +1,82 @@ +#include +#include +#include + +typedef unsigned char BYTE; + +int stringToByte(char* input, BYTE* output){ + + int i; + int loop; + + loop = 0; + i = 0; + while (input[loop] != '\0'){ + //printf("output : %d input : %d /", output[i], input[i]); + output[i] = input [loop]; + i++; + loop++; + //printf("output2 : %d input2 : %d\n", output[i],input[i]); + } +} + +long long convert(int n) { + long long bin = 0; + int rem, i = 1; + + while (n!=0) { + rem = n % 2; + n /= 2; + bin += rem * i; + i *= 10; + } + + return bin; +} + +int main (int argc, char **argv){ // **argv ou *argv[] + + FILE* flux; + + int longueurInstru; + + int i; + + int a[10]; + + int c,k,y=0; + + int test; + + BYTE *instruction = malloc(64*sizeof(int)); + BYTE arr[50]; + + flux= fopen(argv[1], "r"); + + if (flux == NULL){ + perror("fopen"); + return EXIT_FAILURE; + } + + if (flux){ + while (fscanf(flux, "%[^\n] ", instruction) != EOF) { + longueurInstru = strlen(instruction); + stringToByte(instruction, arr); + for (i=0; i