Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4000992
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:51:00+00:00 2026-05-20T07:51:00+00:00

For unpacking complex binary strings with mixed doubles and integers using Ruby’s String.unpack I

  • 0

For unpacking complex binary strings with mixed doubles and integers using Ruby’s String.unpack I need to determine offsets within the binary string. Commonly, doubles are 8 bytes and integers are 4 bytes, but in order to make my code machine-independent, I would like to query these sizes from within my Ruby code.

What is the easiest way to determine the size of integers and doubles from within Ruby, i.e., request the response of a request to C’s sizeof( type ) method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:51:01+00:00Added an answer on May 20, 2026 at 7:51 am

    I have found a workable solution, by using Array#pack, the inverse method of String#unpack. By packing a string of 1 integer or 1 double it is possible to determine the size of integers and doubles from within ruby itself which gives the same results as using sizeof(int) or sizeof(double) (because of the implementation of Array#pack in C):

    [1.to_i].pack("i").size # 4
    [1.to_f].pack("d").size # 8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would the best way of unpacking a python string into fields I have
I am trying to get a grip around the packing and unpacking of binary
I'm using virtualenv and I need to install psycopg2. I have done the following:
Python provides the * operator for unpacking a list of tuples and giving them
# Example: provide pickling support for complex numbers. try: complex except NameError: pass else:
I'm currently unpacking one of blizzard's .mpq file for reading. For accessing the unpacked
The textbook examples of multiple unpacking assignment are something like: import numpy as NP
I'm looking for an easy way of packing/unpacking data structures for sending over the
I'm trying to optimize some bit packing and unpacking routines. In order to do
Is there some code or a library that lets me control the 7-Zip unpacking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.