8位到16位转换 [英] 8bit to 16bit conversion

查看:443
本文介绍了8位到16位转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个捕获8位的图像.我正在寻找将8位值转换为16位.我使用了以下

I have an image which captures 8 bit. I'm looking to convert the 8 bit values to 16 bit. I used the following

short temp16 =  (short)val[i] << 8 ;

其中val是8位样本的数组.

where val is an array of 8 bit samples.

以上说法很吵. 有人可以建议将8bit转换为16bit的方法吗?

The above statement makes noisy. Can anybody suggest a method for 8bit to 16bit conversion?

推荐答案

纯位移位不会给您纯白色. 0xff<< 8 == 0xff00,而不是预期的0xffff.

Pure bitshifting won't give you pure white. 0xff << 8 == 0xff00, not 0xffff as expected.

一个技巧是使用val [i]<< 8 + val [i]并记住正确的数据类型(大小,有符号性).这样,您将获得0x00-> 0x0000和0xff-> 0xffff.

One trick is to use val[i] << 8 + val[i] and remember proper datatypes (size, signedness). That way you get 0x00 -> 0x0000 and 0xff -> 0xffff.

这篇关于8位到16位转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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