driver_output_term() and unsigned long (32 bit) values

Raimo Niskanen raimo@REDACTED
Sat Jul 27 01:25:38 CEST 2002


Scott Lystig Fritchie wrote:
> 
> Am I correct in assuming that, if I *really* needed a driver to get
> the most-significant bit of a 32 bit unsigned long sent to Erlang via
> driver_output_term(), I'm out of luck?
> 
> I suppose I could do something like:
> 
> 1. Modify BEAM to support unsigned integers.
> 2. Send the unsigned int back as a binary and then unpack it as an
> ":32/unsigned-integer"
> 3. Send the unsigned int back as a signed int, then have Erlang pack
> it into a binary and then unpack it as a ":32/unsigned-integer".

3b. Send the unsigned int back as a signed int, then if the returned
value is negative: add (1 bsl 32), otherwise it is correct.

This assumes a 32 bit 2-complement machine. A portability freak would
first find the wordsize in some way (for the day a 64-bit Erlang port
comes), but I do not think non 2-complement machines even exist nor ever
will. 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



> 4. Send back a {1, N} tuple and then have Erlang convert via "(1 bsl
> 31) bor N" or equivalent arithmetic.
> 5. Not use driver_output_term().
> 6. Um, I think I'd better stop now.  This is getting too ugly.
> 
> Is there a better, non-ugly solution I'm missing?
> 
> -Scott



More information about the erlang-questions mailing list