Thread overview | |||||
---|---|---|---|---|---|
|
November 21, 2013 bitwise operation and type | ||||
---|---|---|---|---|
| ||||
why this fail http://www.dpaste.dzfl.pl/a6d6acf4 I want to works with ubyte -> 0000 0000 i do not want use int for manipulating these byte and consume more memory as need! |
November 21, 2013 Re: bitwise operation and type | ||||
---|---|---|---|---|
| ||||
Posted in reply to bioinfornatics | On Thursday, November 21, 2013 08:21:37 bioinfornatics wrote:
> why this fail http://www.dpaste.dzfl.pl/a6d6acf4
>
> I want to works with ubyte -> 0000 0000
> i do not want use int for manipulating these byte and consume
> more memory as need!
All arithmetic operations on integer types (including bitwise manipulations) operate on the original type or (u)int (whichever is larger). So, if you want to manipulate a ubyte and then assign the result to a ubyte, you need to cast it. It's the same with C/C++ except that C/C++ just silently do the cast for you, whereas D requires an explicit cast for narrowing conversions.
- Jonathan M Davis
|
November 21, 2013 Re: bitwise operation and type | ||||
---|---|---|---|---|
| ||||
Posted in reply to bioinfornatics | On 11/20/2013 11:21 PM, bioinfornatics wrote: > why this fail http://www.dpaste.dzfl.pl/a6d6acf4 as with c, most of the integer operators return int for integral types smaller than int. also, this is a case where a += b does something different than a = a + b i guess the former automatically inserts a cast or something. > > I want to works with ubyte -> 0000 0000 > i do not want use int for manipulating these byte and consume more > memory as need! tough. use a cast. |
Copyright © 1999-2021 by the D Language Foundation