[erlang-questions] Float to binary

Bob Cowdery bob@REDACTED
Tue Mar 22 09:12:54 CET 2011


On 22/03/2011 01:24, Richard O'Keefe wrote:
> On 22/03/2011, at 11:27 AM, Bob Cowdery wrote:
>
>> Its part of a binary that gets sent to a device. Its not actually a
>> scaling factor its simply a conversion from MHZ to Hz. 1 MHz =
>> 1000000Hz.
> Er, that _is_ a scaling factor.
Yes, you are right in that it is a multiplier. It's just that I
differentiate between a scaling factor which changes the value and
something that changes only the units, which I call a conversion factor.
I don't think its worth arguing over.
>> The frequency internally is a float but needs to be a 32 bit
>> big-endian number in Hz to send to the device.
> So will   Hz = round(1000000 * MHz)  do?
Exactly what I have. Then I need to inset it in a binary as part of the
protocol packet to a device. I keep all the protocol fragments as
binaries and just combine them in different ways depending on what I am
sending to the device. If that's wrong please say how else you think
that should be done. I'm still a beginner in Erlang!




More information about the erlang-questions mailing list