简体   繁体   English

C中二进制文件的解码器

[英]Decoder for binary files in C

I need to decode text from binary files and compare it with text(which is written by user) in my program and also I need to decode text to binary text.我需要从二进制文件中解码文本并将其与我的程序中的文本(由用户编写)进行比较,并且我还需要将文本解码为二进制文本。 Example:例子:

  1. 011011000110111101101100 => sometext 011011000110111101101100 => 一些文本
  2. sometext => 011011000110111101101100一些文本 => 011011000110111101101100

It should be 2 functions.它应该是2个功能。 How can I do it?我该怎么做?

I understand, so here's how it works :我明白了,所以这是它的工作原理:

  • You need a function can convert 8 bits binary's numbers (can add '0' after the numbers to always have 8bits), every numbers you get can be converted with ASCII table, for exemple l is 108, I assume you already know你需要一个函数可以转换 8 位二进制数(可以在数字后加 ​​'0' 总是有 8 位),你得到的每个数字都可以用 ASCII 表转换,例如 l 是 108,我假设你已经知道
  • an other function can convert ASCII characters to 8bits binary's numbers另一个函数可以将 ASCII 字符转换为 8 位二进制数

Binary to Decimal :二进制到十进制:

01101100 -> 0.2^0 + 0.2^1 + 1.2^2 + 1.2^3 + 0.2^4 + 1.2^5 + 1.2^6 + 0.2^7

it's very easy这很容易

Decimal to Binary : Get the rest and the quotient :十进制转二进制:得到余数和商:

108/2 : q = 54 r = 0
54/2  : q = 27 r = 0
27/2  : q = 13 r = 1
13/2  : q = 6  r = 1
6/2   : q = 3  r = 0
3/2   : q = 1  r = 1

take the last quotient and all rest : 1101100, add a 0 to have 8 bits : 01101100取最后一个商和所有其余部分:1101100,添加一个 0 以获得 8 位:01101100

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM