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

Python provides the * operator for unpacking a list of tuples and giving them
I know it's possible to deploy earlier versions of the .NET framework using AD
I'm trying to set up a project using Maven and am a bit stuck
I understand that these methods are for pickling/unpickling and have no relation to the
So I want to trigger an event (pausing/unpausing some media) whenever the user presses
Windows Logo Program requires that the unins000.exe , generated by Inno, is signed. The
I'm trying to setup fastri (http://eigenclass.org/hiki/fastri) on emacs running on cygwin in windows. The
When installing django-piston from the bitbucket repo with pip, I noticed something weird (first
The spinning globe application unning on the emulator works on android 1.5 as target
I can't seem to install zlib properly, I installed Python from source on Ubuntu10.4

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.