Results 1 to 5 of 5
  1. #1
    Cyaphex's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    21
    Reputation
    10
    Thanks
    0
    My Mood
    Confused

    I need PHP help.

    function hex2bin($str) {
    $bin = "";
    $i = 0;
    do {
    $bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
    $i += 2;
    } while ($i < strlen($str));
    return $bin;
    }

    Xampp is telling me theres something wrong on the last line (174) which would be the }, but there isn't a problem with it at all

  2. #2
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Ah we-a blaze the fyah, make it bun dem!

  3. #3
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    You don't index into arrays with curly braces "{}" to index arrays in PHP, you use square ones [].

    i.e:
    Code:
    $bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
    Should actually be
    Code:
    $bin .= chr(hexdec($str[$i].$str[$i + 1]));
    However this code isn't going to do what the function name implies (convert a hexadecimal string into a binary string).

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  4. #4
    Cyaphex's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    21
    Reputation
    10
    Thanks
    0
    My Mood
    Confused
    I know, It's not my original code, i'm setting up a server, actually and it was one of the errors it was recieving.

  5. #5
    kalekip1's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    the Netherlands
    Posts
    519
    Reputation
    22
    Thanks
    315
    My Mood
    Amused
    Quote Originally Posted by Jason View Post
    You don't index into arrays with curly braces "{}" to index arrays in PHP, you use square ones [].

    i.e:
    Code:
    $bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
    Should actually be
    Code:
    $bin .= chr(hexdec($str[$i].$str[$i + 1]));
    However this code isn't going to do what the function name implies (convert a hexadecimal string into a binary string).
    It doesn't matter. PHP is weird, but still a nice language. Curly braces (a.k.a. curly brackets: { }) as well as braces (a.k.a. brackets: [ ]) are just fine. People tend to use brackets because that looks better.

    @Cyaphex Do you still need help? Cause I might have the solution for you. You should clearify your question how ever.

    Edit:
    Code:
    <?php
    $convert = '01234567890abcdef';
    $convertFrom = 16; //Hexadecimal
    $convertTo = 2; //Binary
    echo base_convert($hex, $converFrom, $convertTo);
    ?>
    Both $convertFrom and $convertTo have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35. You probably don't want to change this, since you only want a hex2bin. If you want bin2hex, just swap the variables.
    Last edited by kalekip1; 08-27-2013 at 01:21 PM.


Similar Threads

  1. [Help Request] FET I NEED YOUR HELP! PM ME!
    By FetJr in forum Combat Arms Help
    Replies: 3
    Last Post: 07-08-2011, 09:29 AM
  2. [Help Request] need serious help guys
    By pyrozombie in forum Call of Duty Modern Warfare 2 GSC Modding Help/Discussion
    Replies: 7
    Last Post: 06-09-2011, 10:29 AM
  3. [Help Request] Need some help to make a bot
    By Domo in forum Vindictus Help
    Replies: 6
    Last Post: 05-21-2011, 10:15 AM
  4. [Help Request] I need some help with binding eps7
    By v1zhaixingv1 in forum Vindictus Help
    Replies: 3
    Last Post: 05-18-2011, 09:25 PM
  5. [Help Request] please i need ur help norton deleted (crossfire.exe) and the game stoped
    By nooraleman in forum CrossFire Help
    Replies: 22
    Last Post: 05-14-2011, 07:00 PM