Jump to content

Recommended Posts

How would someone go about creating a byte array in PHP?

 

I see google results for C# and maybe a few VB results, but no PHP.

Basically, what I want to do is take a binary string, and then convert it to 13 bytes.

 

I would then like to convert those bytes to display in hexadecimal form.

something like this?

 

00 00 00 0D 13 8A 87 BA B5 CF 38 04 B1

(There are 13 listed)

 

Please help!

 

Thanks in advance!

 

Link to comment
https://forums.phpfreaks.com/topic/118029-php-byte-array/
Share on other sites

sorry, bin2hex does not really do what I need to do.

 

i first need to essentially  "split" the code up into 13 bytes?

I really don't know how to phrase it better than that.

I've only started working with bits/bytes.

 

Anyway, I do want each byte to be changed to a  hex when it is split.

 

So we have step 2, but we still need to figure out step 1....

Link to comment
https://forums.phpfreaks.com/topic/118029-php-byte-array/#findComment-607204
Share on other sites

Thanks Ken, right before I read your post, ShaunO's idea worked...somewhat

However, it is really odd, let me show everyone an output.

 

first, I have the hex that I want (d138a87bab5cf3804b1);

so I convert it to a decimal and it matches the variable!

but when I try to convert back to a hexidecimal... things go WRONG.

Have a look...

 

/* $tb = 6.17512345671E+22 (integer) */

echo '<br />Test: ' . base_convert($tb, 10, 16);
echo '<br />Test 2: ' . base_convert((hexdec('d138a87bab5cf3804b1')), 10, 16);

/* both ouput 382994669bd2 when converted to hex */

 

I just don't get it, I think decimals and hexidecimals should be able to convert.

Maybe it is too big of a number?

Link to comment
https://forums.phpfreaks.com/topic/118029-php-byte-array/#findComment-607219
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.