/    Sign up×
Community /Pin to ProfileBookmark

Binary representation

Hi!

I have a question regarding type conversion and memory storage. I’ve looked around after functions for appropriate conversion, but haven’t found any yet.

What I’m tring to do is to convert double, int and strings to binary format. Or more pricesely to the format used to store these types in memory. In C++/Java this is known as the byte-type. For instance, a int would be stores as four consequtive bytes in memory.

I’m found diverse functions like decbin(…), base_convert(…), pack(…), etc., but no functions that can help. So, to precisely define the problems:

  • Coversion of a int to a byte array (4 bytes, little endian)

  • Coversion of a double to a byte array (8 bytes, little endian)

  • Conversion of a string to a byte array (x bytes)

  • Write these the contents of these arrays to file (binary files)
  • Does anyone has any suggestions on how this may be done? Really appreciated!

    to post a comment
    PHP

    0Be the first to comment 😎

    ×

    Success!

    Help @per2008 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...