如何获得按位表示 [英] How to get bit wise representation

查看:87
本文介绍了如何获得按位表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我尝试获取一个中文字符的字节数时,它显示每个字符对应的1至4个字节,还发现每个字符的Dec值都大于127,因此我需要7位长度的每个字节,其余的将转换到下一个字节级别,以使Dec值小于127.

例如227,131,162是字符``モ''的字节级表示,因此我需要从第一个字节级获取7位并将剩余的一位移至下一个字节级(即131).获得的每个12月表示形式均小于127.

请帮帮我

Hi,

When I tried to get number of bytes of a character in chinese it displayed 1 to 4 bytes corresponds to each character.Also found that the Dec values of each one is greater than 127.So I need each one in 7 bit length and remaining will shift to next byte level inorder to get the Dec value less than 127.

For example 227,131,162 is the byte level representation of the character ''モ''.So what I need is to get 7 bit from first byte level and shift remaining one bit to next byte level(that is to 131).From this I will get each Dec representation less than 127.

Please help me
Thanks in advance.

推荐答案

227,131,162与E3 83 A2的十六进制相同.如果将此值右移1位,将得到71 C1 D1,即113,193,209.因此,您仍然没有想要的东西,而且这些值代表了完全不同的字符.
227,131,162 is the same as E3 83 A2 in hexadecimal. If you shift this value 1 bit right you will get 71 C1 D1 which is 113,193,209. So you still don''t have what you want and also these values represent a totally different character. Perhaps your explanation needs to be made clearer.


加密不需要7位字符-它适用于字节数据(8位).您的汉字将被当作字节数据并正确编码(和解码),而无需您使用数据位.


我正在尝试加密每个字符,以使字符数组产生大量数据,就像滴数导致水一样.现在我们偏离了实际目的.请问您对我提出的要求有任何想法吗? "

我认为这不会对您有太大帮助,因为生成的字符"仍然无法打印,但是...
试试:
Encryption does not need 7 bit characters - it works on byte data (which is 8 bit). Your Chinese characters will be taken as byte data and encoded (and decoded) correctly without the need for you to play with the data bits.


"I am trying to encrypt each character so that an array of character results a chunk of data as like number of drops results a water.Now we are deviating the actual purpose.Could you please give any idea about what I am asked"

I don''t think it is going to help you much, as the "characters" is generates are still not printable, but...
Try:
byte[] data = new byte[3];
Random r = new Random();
r.NextBytes(data);
char[] chars = new char[4];
chars[0] = (char) (data[0] & 0x7f);
chars[1] = (char) (((data[0] & 0x80) >> 7) | ((data[1] & 0x3F) << 1));
chars[2] = (char) (((data[1] & 0xC0) >> 6) | ((data[2] & 0x1F) << 2));
chars[3] = (char) (((data[2] & 0xE0) >> 5));



如果您输入的数据是:



If your input data is:

b0    abcd efgh
b1    ijkl mnop
b2    qrst uvwx


然后将其视为最低有效位流并生成:


then this treats it as a least significant bit stream and generates:

c0     bcd efgh
c1     klm nopa
c2     tuv wxij
c3          qrs

尽管使用适当的"加密算法,您仍然可能会更好,尽管...

You will still probably be better off going with a "proper" encryption algorithm, though...


这篇关于如何获得按位表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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