开发者

How to write this php code in c++

开发者 https://www.devze.com 2023-02-03 18:35 出处:网络
$x开发者_如何学JAVA = pack(\"N\", $num1).pack(\"N\", $num2).$data; I am trying to do it with union unionchal {
$x开发者_如何学JAVA = pack("N", $num1).pack("N", $num2).$data;

I am trying to do it with

 union unionchal {
  struct ast{
   unsigned long a;
   unsigned long b;
   char c[8];
  } chal;
  unsigned char response[16];
 };

ast being the input and response being the output

It is meant to output yp¶ ‚¬þÖHpö€ì_± but gives ¶pyßêÈ)ÖHpöì_

I think it's got something to do with it being big endian byte order


Try using htonl on your integers before placing them into the structure. It will convert them into big-endian order. If you need 64-bit longs, see the discussion about it on SE.


I think it's got something to do with it being big endian byte order

I also think so. You may use htonl() for example, to change the byte order on little-endian machines, or write your own byte-swapping function (but then you'll have to test yourself what the byte order of the host machine is).


Try using Boost Variant library.

0

精彩评论

暂无评论...
验证码 换一张
取 消