gpt4 book ai didi

java - 是否可以使用 360 int 到 1 字节对其进行解码/编码而不丢失一些值

转载 作者:行者123 更新时间:2023-12-02 04:05:18 24 4
gpt4 key购买 nike

是否可以使用 360 int 到 1 字节对其进行解码/编码而不丢失一些值

我目前正在寻找一种方法来减少 360 以适应一个字节的最大值 255。

这是我尝试过的:

  public static int getBearing(byte data){
return Integer.parseInt( Integer.toHexString(data & 0xff) , 16) << 1;
}
public static void main(String[] args){
for(int bearing = 0 ; bearing < 360 ; bearing++){
final byte bearingByte = (byte) (bearing >> 1);
System.out.printf("Bit {%s} , Original Bearing {%d} , Decrypted Bearing {%d} \n" , get8Bit(bearingByte) , bearing , getBearing(bearingByte));
}
}

输出是:

Bit {00000000} , Original Bearing {0} , Decrypted Bearing {0} 
Bit {00000000} , Original Bearing {1} , Decrypted Bearing {0} <-- this should be 1
Bit {00000001} , Original Bearing {2} , Decrypted Bearing {2}
Bit {00000001} , Original Bearing {3} , Decrypted Bearing {2} <-- this should be 3
Bit {00000010} , Original Bearing {4} , Decrypted Bearing {4}
Bit {00000010} , Original Bearing {5} , Decrypted Bearing {4} <-- this should be 5
Bit {00000011} , Original Bearing {6} , Decrypted Bearing {6}
Bit {00000011} , Original Bearing {7} , Decrypted Bearing {6} <-- this should be 7
Bit {00000100} , Original Bearing {8} , Decrypted Bearing {8}
Bit {00000100} , Original Bearing {9} , Decrypted Bearing {8} <-- this should be 8

看起来解密后的所有内容都是偶数。

Is there a formula or trick so that i could not lose some value?

最佳答案

Is it possible to decode/encode this without losing some value using 360 int to 1 byte.

没有。这是不可能的。

从较大域(360 个值)到较小域(256 个值)的任何编码都必须是有损的1

<小时/>

1 - 证明这一点的一种方法是应用“pigeonhole principle ”。

关于java - 是否可以使用 360 int 到 1 字节对其进行解码/编码而不丢失一些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34347935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com