将32位unsigned int转换为16位signed int。 [英] Convert 32 bit unsigned int to 16 bit signed int.

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

问题描述

您好

我正在寻找一种将32位无符号

整数转换为16位有符号整数的有效方法。我想要的是32位无符号整数的低16位

,其中15位(0..15)用作16位的

符号位有符号整数。任何想法/帮助很大

赞赏。


谢谢。

Hello
I am looking for some effecient way to convert a 32 bit unsigned
integer to a 16 bit signed integer. All I want is the lower 16 bits
of the 32 bit unsigned integer , with bit 15 (0..15) to used as the
sign bit for the 16 bit signed integer. Any ideas/help greatly
appreciated.

Thanks.

推荐答案

9月11日,12:56 * pm,Fore< brian.william ... @ blueyonder.co.ukwrote:
On Sep 11, 12:56*pm, Fore <brian.william...@blueyonder.co.ukwrote:

Hello

我正在寻找一种将32位无符号

整数转换为16位有符号整数的有效方法。 *我想要的是32位无符号整数的低16位

,其中15位(0..15)用作16的

符号位位有符号整数。 *任何想法/帮助很大

赞赏。
Hello
I am looking for some effecient way to convert a 32 bit unsigned
integer to a 16 bit signed integer. *All I want is the lower 16 bits
of the 32 bit unsigned integer , with bit 15 (0..15) to used as the
sign bit for the 16 bit signed integer. *Any ideas/help greatly
appreciated.



1.删除有效一词来自你的词典。研究Knuth's /

Hoare'定律。

2.你没有研究过按位运算符吗?

1. Remove the word "efficient" from your lexicon. Study Knuth''s/
Hoare''s law.
2. Have you not studied the bitwise operators?


9月11日21:31,red floyd< redfl ... @ gmail.comwrote:
On 11 Sep, 21:31, red floyd <redfl...@gmail.comwrote:

9月11日,12:56 * pm, Fore< brian.william ... @ blueyonder.co.ukwrote:
On Sep 11, 12:56*pm, Fore <brian.william...@blueyonder.co.ukwrote:

你好

我正在寻找一些有效的转换方式32位无符号

整数到16位有符号整数。 *我想要的是32位无符号整数的低16位

,其中15位(0..15)用作16的

符号位位有符号整数。 *任何想法/帮助很大

赞赏。
Hello
I am looking for some effecient way to convert a 32 bit unsigned
integer to a 16 bit signed integer. *All I want is the lower 16 bits
of the 32 bit unsigned integer , with bit 15 (0..15) to used as the
sign bit for the 16 bit signed integer. *Any ideas/help greatly
appreciated.



1.删除有效一词来自你的词典。 *研究Knuth''s /

Hoare'定律。

2.你没有研究过按位运算符吗?


1. Remove the word "efficient" from your lexicon. *Study Knuth''s/
Hoare''s law.
2. Have you not studied the bitwise operators?



回答1.我接受删除有效和无法......法律。

回答2.是的,但我也希望能够实现这个

,而不会有关于可能丢失数据的大量编译器警告。

Answer to 1. I accept removal of efficient and no to ...laws.
Answer to 2. is yes, but I also want to be able to achieve this
without a host of complier warnings about the possible loss of data.


Fore写道:
Fore wrote:

9月11日21:31,red floyd< redfl ... @ gmail.comwrote:
On 11 Sep, 21:31, red floyd <redfl...@gmail.comwrote:

> 9月11日下午12:56,Fore< brian.william ... @ blueyonder.co.ukwrote:
>On Sep 11, 12:56 pm, Fore <brian.william...@blueyonder.co.ukwrote:

>> Hello 符号位。任何想法/帮助都非常赞赏。
>>Hello
I am looking for some effecient way to convert a 32 bit unsigned
integer to a 16 bit signed integer. All I want is the lower 16 bits
of the 32 bit unsigned integer , with bit 15 (0..15) to used as the
sign bit for the 16 bit signed integer. Any ideas/help greatly
appreciated.


1.删除有效一词来自你的词典。研究Knuth's /
Hoare'定律。
2。你没有研究过按位运算符吗?

1. Remove the word "efficient" from your lexicon. Study Knuth''s/
Hoare''s law.
2. Have you not studied the bitwise operators?



回答1.我接受删除有效和无法......法律。

回答2.是的,但我也希望能够实现这个

,而不会有关于可能丢失数据的大量编译器警告。


Answer to 1. I accept removal of efficient and no to ...laws.
Answer to 2. is yes, but I also want to be able to achieve this
without a host of complier warnings about the possible loss of data.



如果编译器警告困扰你,请禁用它们。从32位变为16位* b $ b位*将导致*数据丢失(前16位),编译器不能让没有警告* b $ b除非*你告诉它不要警告你。


V

-

请在回复时删除资本''A'电子邮件

我没有回复最热门的回复,请不要问

If compiler warnings bother you, disable them. Going from 32 bits to 16
bit *will cause* loss of data (the top 16 bits), the compiler cannot let
it go without a warning *unless* you tell it not to warn you.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


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

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