整数编码 [英] Integer encoding
问题描述
integer = 0,编码为3294
integer = 1,编码为128
整数= 2,编码为2098
等。
我该怎么做?我看过函数dec2bin,但这不是我需要的。我的输入将是一个向量,例如 x = [2 1 0]
,输出将为向量 y = [2 0 9 8 1 2 8 3 2 9 4]
。
任何建议或帮助都是赞赏!
编码可能不成为描述这个的最好的话。这个答案只是搜索中的一个方向。
我会看看任何字典
, hashtable
或 map
数据结构。以下代码基于此帖中描述的解决方案
c = containers.Map;
c('0')= 3294;
c('1')= 128;
c('2')= 2098;
键(c)
值(c)
您可能需要添加正确使用,也可以直接使用整数类型来删除转换和转换开销。
I am trying to figure out how to encode integers based on given parameters. For example, I am given the table:
integer = 0, encoding is 3294
integer = 1, encoding is 128
integer = 2, encoding is 2098
etc.
How would I go about doing this? I have looked at the function dec2bin, but it's not exactly what I need. My input would be a vector, say x = [ 2 1 0 ]
and the output would be the vector y = [2 0 9 8 1 2 8 3 2 9 4]
.
Any advice or help is appreciated!
Encoding may not be the best word to describe this. This answer is just a direction in your search.
I would have a look at any dictionary
, hashtable
or map
data structures. Code below is based on solution described in this post
c = containers.Map;
c('0') = 3294;
c('1') = 128;
c('2') = 2098;
keys(c)
values(c)
You may need to add proper usings and maybe use integers types directly to remove casts and conversion overhead.
这篇关于整数编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!