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 9320675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:41:44+00:00 2026-06-19T03:41:44+00:00

Attempting to convert a UID generator from Javascript to Ruby, I wanted to understand

  • 0

Attempting to convert a UID generator from Javascript to Ruby, I wanted to understand the following behavior.

this line of code

89190868196442450 | 0

would give in javascript

1074708816

and in ruby

89190868196442450

I fully understand the ruby behavior as Bitwise OR operator copies a bit if it exists in eather operand, but I’m still puzzled regarding the javascript behavior.
I looked deeper in javascript integer representation and could not find a clear explanation. I found this, but did not fully get it.

89190868196442450 in binary is 100111100110111101001111101000000000011101100000101010010 which makes it 57 bits length.

Could anyone give me a clear explanation or the above result. And what operation should I do on the ruby code to ensure similar behavior?

  • 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-19T03:41:46+00:00Added an answer on June 19, 2026 at 3:41 am

    If you want to represent numbers with > 32 bits and perform bitwise operations on them in Javascript, you’re better off using an emulated long such as this: http://closure-library.googlecode.com/svn/docs/class_goog_math_Long.html.

    Take a look at this entry. Technically Javascript can represent 2^53 ints, but bitwise ops are limited to 32 bits.

    What is JavaScript's highest integer value that a Number can go to without losing precision?

    To elaborate, what’s happening in JS when you do 89190868196442450 | 0 is Javascript is taking the least significant 32 bits and ORing them with 0, which yields 1074708816, and in Ruby it is ORing it with all of the bits. If for some reason you wanted to reproduce that in Ruby, you would AND your number with 1FFFFFFFF so you’re only operating on the least significant 32 bits and then OR it by 0 (which does nothing but would give you the same result).

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

Sidebar

Related Questions

I am attempting to convert the following HQL query to Criteria. from SubportfolioAudit as
Im attempting to Convert a Price (from an API (code below)). public class Price
I am attempting to convert some code from TWebBrowser to Chromium but am having
I am attempting to create a variable or string from Convert.ToChar(b[i]) within the following
I'm attempting to convert a string from CP932 (aka Windows-31J) to utf8 in javascript.
I'm attempting to convert some of my code from Tkinter to wxPython. Currently I'm
I'm attempting to convert a string to a TStream. My code below gives me
I'm attempting to convert dates from one format to another: From e.g. October 29,
This is what I'm attempting to convert to python This is where I get
I am New to Ada and I am attempting to convert the code in

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.