0

Try bitshifting for a Uint32 in Dart. How to handle this, if there is no support from dart:ffi?

import 'dart:ffi';


Uint32 len = 0 as Uint32;
len >>= 1; // will not be compiled

Try it with "normal" int. But i am afraid, will the result be everytime the same as using Uint32?

julemand101
  • 28,470
  • 5
  • 52
  • 48
  • `Uint32` does not have a bitshift operator. FFI is for interfacing to C functions and the types defined in the FFI package are for marking type signatures in FFI interfaces. If you want to do a bitshift specifically on a 32 bit unsigned, you can make a C function to do that and link it through FFI. If you want to do a bitshift in Dart, just use the normal `int` type. The result will be nearly always be the same. Just take a look at the C spec and Dart docs to compare the operators to see differences. It would help to better understand your intentions so that we can help you find a solution. – Christopher Moore Nov 14 '22 at 14:23

1 Answers1

0

The Uint32 type represents native values. There is no Dart value with that type, so your as Uint32 cast will fail.

If you have a Pointer<Uint32>, then you can use that to refer to the native value. Example:

Pointer<Uint32> p = ...;
p.value >>= 1;
lrn
  • 64,680
  • 7
  • 105
  • 121