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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:10:32+00:00 2026-05-24T11:10:32+00:00

I have a piece of Javascript code I’m trying to understand // read big-endian

  • 0

I have a piece of Javascript code I’m trying to understand

// read big-endian (network byte order) 32-bit float
readFloat32 = function(data, offset) {
    var b1 = data.charCodeAt(offset) & 0xFF,
        b2 = data.charCodeAt(offset+1) & 0xFF,
        b3 = data.charCodeAt(offset+2) & 0xFF,
        b4 = data.charCodeAt(offset+3) & 0xFF;
    var sign = 1 - (2*(b1 >> 7));       //<--- here it is and 2 lines below
    var exp = (((b1 << 1) & 0xff) | (b2 >> 7)) - 127;
    var sig = ((b2 & 0x7f) << 16) | (b3 << 8) | b4;
    if (sig == 0 && exp == -127)
      return 0.0;
    return sign * (1 + sig * Math.pow(2, -23)) * Math.pow(2, exp);
}

what does “>>” mean? Is it a special type of boolean (like ‘<‘ or ‘>’)

  • 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-24T11:10:33+00:00Added an answer on May 24, 2026 at 11:10 am

    These are the shift right (with sign) and shift left operators.

    Essentially, these operators are used to manipulate values at BIT-level.
    They are typically used along with the the & (bitwise AND) and | (bitwise OR) operators and in association with masks values such as the 0x7F and similar immediate values found the question’s snippet.
    The snippet in question uses these operators to “parse” the three components of a 32 bits float value (sign, exponent and fraction).

    For example, in the question’s snippet:
    1 - (2*(b1 >> 7)) produces the integer value 1 or -1 depending if the bit 7 (the 8th bit from the right) in the b1 variable is zero or one respectively.
    This idiom can be explained as follow.

    • at the start, b1, expressed as bits is 0000000000000000abcdefgh
      note how all the bits on the left are zeros, this comes from the
      b1 = data.charCodeAt(offset) & 0xFF assignement a few lines above, which essentially zero-ed all the bits in b1 except for the rightmot 8 bits (0xFF mask).
      a, b, c… thru h represent unknown boolean values either 0 or 1.
      We are interested in testing the value of a.
    • b1 >> 7 shifts this value to the right by 7 bits, leaving
      b1 as 00000000000000000000000a which, read as an integer will have value 1 or 0
    • this 1 or 0 integer value is then multiplied by 2
      it is then either 2 or 0, respectively.
    • this value is then substracted from 1, leaving either -1 or 1.

    Although useful to illustrate the way the bit-operators work, the above idiom could be replaced by something which tests the bit 7 more directly and assigns the sign variable more explicitly. Furthermore this approach does not require the initial masking of the leftmost bits in b1:

    var sign
    if (b1 & 0x80)   // test bit 7  (0x80 is  [00000000]10000000)
      sign = -1;
    else
      sign = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of javascript code that I am trying to understand return
Recently I saw this piece of JavaScript code, but have been unable to understand
I have this piece of code in javascript: var catId = $.getURLParam(category); In my
I have piece of javascript code, which should process when the browser window is
I have a piece of Javascript code that uses an XHR to POST data
I have a piece of JavaScript code which is expected to set an integer
I have a piece of javascript code like this right now. document.getElementById(pos).style.backgroundColor='#800080'; I want
Does anyone have a piece of JavaScript code that creates a cookie and stores
Below i have pasted my piece of javascript code here 1) function showCustomerName(dropdown) {
I have a piece of javascript code. Right now it forces users to manually

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.