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

  • SEARCH
  • Home
  • 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 8149789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:55:17+00:00 2026-06-06T14:55:17+00:00

I am experiencing some confusion on the Kernel#sprintf method in Ruby. Ruby 1.9 handles

  • 0

I am experiencing some confusion on the Kernel#sprintf method in Ruby.

Ruby 1.9 handles encoding in a different way than Ruby 1.8.

Here are the results I am after, and how it behaves in Ruby 1.8:

>> RUBY_VERSION
=> "1.8.7"
>> sprintf("%c", 88599)
=> "\027"

This is how it behaves in Ruby 1.9:

1.9.3p194 :001 > RUBY_VERSION
=> "1.9.3" 
1.9.3p194 :002 > sprintf("%c", 88599)
=> "\u{15A17}"

If I use the magic comment to set the encoding to binary (ascii-8bit) I get an error:

1.9.3p194 :001 > RUBY_VERSION
=> "1.9.3" 
1.9.3p194 :002 > # encoding: binary
1.9.3p194 :003 >   sprintf("%c", 88599)
RangeError: 88599 out of char range
from (irb):3:in `sprintf'
from (irb):3
from /Users/lisinge/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

I have also tried this with Ruby 1.9.2 so there doesn’t seem to be specific to 1.9.3.

Maybe I am doing something wrong? I am not so familiar with the Kernel#sprintf method.

I am using a smpp library called ruby-smpp which can be found on github. It is the send_concat_mt method on line #47 that is acting up when i am trying to run it in Ruby 1.9.3.

I would greatly appreciate it if any of you could shed some light on this matter.

  • 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-06-06T14:55:18+00:00Added an answer on June 6, 2026 at 2:55 pm

    The sprintf documentation states:

    Field |  Other Format 
    ------+--------------------------------------------------------------
      c   | Argument is the numeric code for a single character or
          | a single character string itself.
    

    88599 is not a valid numeric code for a single character in the default behavior for Ruby 1.8; which, I believe, is no encoding. What it appears to be doing is doing a mod 256 on the value you supply and then converting it:

    % irb
    1.9.3-p194 :003 > 88599 % 256 == 027
     => true 
    

    As to you doing something wrong, no. What did happen is that allowing out-of-bounds character codes was a bug that has been fixed by Ruby 1.9 which now properly throws an exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing some problem on UTF-8 Encoding. I have a CSV file and
I'm experiencing some strange behavior for which I can't find any documented knowledge. Here's
I am experiencing some confusion with jquery.validate.js First of all, what is MicrosoftMvcJqueryValidation.js. It
After experiencing some performances issues on my client side, we decided to give a
I am experiencing some confusion in the use and purpose of Spring's DataBinder and
I am experiencing some different javascript behavior when running my site on Kindle Fire
i am experiencing some weird behaviour here. i am using the following code to
I'm currently experiencing some problems with my server. I have a pool which is
We are experiencing some random NetConnection.Call.Failed: HTTP: Failed when using the flex 4 mx.messaging.channels::SecureAMFChannel
I am experiencing some very odd timing behavior from a function I wrote. If

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.