---
# System prepended metadata

title: Differents between Binary and ASCII

---

# Differents between Binary and ASCII

###### ***Use integer with 4 bytes as example : 00000000 00000000 00000011 11011011 = 987***

## Binary Input / Output

### fread
##### While using fread, it reads binary data just like [above](#Use-integer-with-4-bytes-as-example--00000000-00000000-00000011-11011011--987)
```c=
fread(&a, sizeof(int), 1, flie_ptr) //reads sizeof(int) * 1 = 4 bytes as total
a == (00000000)₂(00000000)₂(00000011)₂(11011011)₂ == 987 
```

### fwrite

##### While using fwrite, it writes binary on file and displays ASCII = (NUL)(NUL)(ETX) �
```c=
fwrite(&a, sizeof(int), 1, file_ptr); //writes sizeof(int) * 1 = 4 bytes as total
/* Above Equals to Below */
fwrite((00000000)₂, sizeof(char), 1, fileptr); //NULL
fwrite((00000000)₂, sizeof(char), 1, fileptr); //NULL
fwrite((00000011)₂, sizeof(char), 1, fileptr); //ETX(End of Text)
fwrite((11011011)₂, sizeof(char), 1, fileptr); // �
```

## ASCII Input / Output

### fscanf

##### While using fscanf, it scans ASCII(char) data
```c=
fscanf(file_ptr, "%d", &a);
a == atoi("987") == 987
```

### fprintf
##### While using fprintf, it prints ASCII
```c=
fprintf(file_ptr, "%d", a);
/* Above Equals to Below */
fprintf(file_ptr, "%c", '9'); // '9' = (00111001)₂
fprintf(file_ptr, "%c", '8'); // '8' = (00111000)₂
fprintf(file_ptr, "%c", '7'); // '7' = (00110111)₂
```

# Always Remember: Display Always Shows ASCII