如果有人知道c ++,请帮助我? [英] Please help me if anyone know c++?

查看:110
本文介绍了如果有人知道c ++,请帮助我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个二进制值01000100和01000010.

我想像这样压缩它们:



Suppose i have two binary values 01000100 and 01000010.
I want to compress them like this:

01000100 = 1
01000010 = 0





压缩后2bytes将转换为2bits

并将它们解压缩如下:





After compress the 2bytes would be converted to 2bits
and decompress them like:

1 = 01000100
0 = 01000010





解压后2bits将转换为2bytes



实际上我想压缩2byte(二进制)到2bits.And after解压缩数据再次转换为2byte。

我如何在visual basic中执行此操作。我是计算机编程的新手



After decompress the 2bits would be converted to 2bytes

Actually i want to compress 2byte(binary) to 2bits.And after decompress the data again convert to 2byte.
How can i do it in visual basic. I am a new in computer programming

推荐答案

如果你只有2个输入和2个输出值,那么非常简单。



Pretty simple if you only have 2 input and 2 output values.

char Compress(char in)
{
  if(68 == in) return 1;  // 01000100 -> 1
  if(66 == in) return 0;  // 01000010 -> 0
  return -1;              // invalid
}

char Decompress(char in)
{
  if(1 == in) return 68;  // 1 -> 01000100
  if(0 == in) return 66;  // 0 -> 01000010
  return -1;              // invalid
}





你的问题描述我觉得这里的问题是......



Your problem description I think was the problem here...


你做不到 - 除了你已经给出的琐碎案例很简单:

You can''t do it - except in the trivial case you are giving already which is easy:
1) Is value equal to 0?
2) if yes, output value is 01000010
3) if no, output value is 01000100



两位只能容纳4个值: br />


Two bits can only hold 4 values:

00
01
10
11



所以其他252你可以进入8位的可能组合无处可存储。压缩算法通过查找数字模式(实质上)并且需要一定量的开销来存储有关压缩方法的信息 - 只有8位数据,没有足够的信息来确定模式 - 并且有了开销,你最终会输出比输入更长!


So the other 252 possible combinations you can get into 8 bits have nowhere to be stored. Compression algorithms work by finding patterns in numbers (in essence) and require an amount of overhead to store information about the compression method - with only eight bits of data there is insufficient information for a pattern to be determined - and with overhead you would end up with a longer output than input!


这篇关于如果有人知道c ++,请帮助我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆