Binary stream read write -C++

Why write files in binary

The physical storage of a computer is binary , Is the difference between a text file and a binary file physical storage ?

No , It's logical , The two are only different at the coding level , Text files are based on character encoding , Common codes are ascll code ,unicode Coding, etc , Binary files are value based files , According to the application , Specify what a value means ( Such a process can be seen as custom coding );

Text files are basically fixed length encoded , Character based , Each character is fixed in the specific encoding ,ascll Code is a specific code , Binary code can be regarded as variable length code

first :

Using binary file to save space , Like storing numbers , Special real number , Binary saves more space

second :

Computer physical memory is stored in binary format , So binary storage to files is faster , If stored as a text file , Process to be converted , So when there's a lot of data , The difference between the two will show

third :

Some more accurate data , Using binary storage will not cause significant bit loss .

The difference between text file and binary file :

*
Write number 1, What is actually written is character '1'

*
Binary : Write numbers 1, The actual write is an integer 1 ;

*
1 The binary of is 0001 ( Occupied 4 Bytes , The lowest is 1, Chasing high 3 All bytes 0);

Write binary

Using the write Method to write binary data .

*
demonstration

Output to an integer :

*
*
Read binary

Using FileStream read method .

*
demonstration

*

*
The output is :

*

*
More technical exchanges welcome ~ Strange cattle

*

Technology
©2019-2020 Toolsou All rights reserved,
ELementUI select Multi select drop-down box to get all properties of the selected item vue use vue-clipboard2 Realize the function of copy link Centos7 lower mysql8.0 To install and change the initial password ; Digital rolling lottery program stay Vue Use in Web Worker( Essence )2020 year 8 month 15 day redis database StackExchange.Redis in Set type (C# edition ) Obviously post Why does the request display parameters in the address bar ?Android 11 Official release !mybatis Return result mapping of series A guess number of small games , use JavaScript realization