perl6 - Converting data in a Blob into a Num

不问归期 提交于 2019-12-10 13:18:09

问题


I've got some bytes in a blob, an immutable buffer for binary data and I am looking for a way to convert what it holds into a floating point data structure, Num, since it is the class that fits all those 3 formats that could be in the $blob

  1. IEEE Float
  2. IEEE Double
  3. IEEE Long Double

What would be the best way of doing that conversion?


回答1:


Import NativeCall, perform a cast to a pointer of desired type and dereference the result:

use NativeCall;
nativecast(Pointer[num32], $blob).deref;


来源:https://stackoverflow.com/questions/50086033/perl6-converting-data-in-a-blob-into-a-num

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!