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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:31:10+00:00 2026-06-09T11:31:10+00:00

I want to encode many things in hex. Here are examples. var LAST_DIGITS =

  • 0

I want to encode many things in hex. Here are examples.

var LAST_DIGITS = 0x000000A7; // Last 2 digits represent something
var MID_DIGITS = 0x00000E00;  // 5th and 6th digits represent something else

Let’s say I added LAST_DIGITS and MID_DIGITS together. That’s 0x00000EA7 and represents the two different things I want to encode.

Is there some way I can just check a subset of that independently, in javascript/HTML5? Or do I have to turn it into a string or other collection and then reference indices explicitly?

In the above example, here’s what I’m looking for

function getThemDigits (inHexValue) 
{
    // Check for 5th and 6th digits through my dream (not real!) function
    inHexValue.fakeGetHexValueFunction(4,5); // returns 0E

    // Check for last two digits for something else
    inHexValue.fakeGetHexValueFunction(6,7); // returns A7
}
  • 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-09T11:31:11+00:00Added an answer on June 9, 2026 at 11:31 am

    The common Bit-Operators (| & >> << etc.) are also available in JavaScript.

    Lets assume that you always want two hexadecimal digits from the hexadecimal representation of that integer. And lets count the index of those digits from the right rather than from the left:

    function GetHex(hex, offset) {
        // Move the two hex-digits to the very right (1 hex = 4 bit)
        var aligned = hex >> (4 * offset);
    
        // Strip away the stuff that might still be to the left of the
        // targeted bits:
        var stripped = aligned & 0xFF;
    
        // Transform the integer to a string (in hex representation)
        var result = stripped.toString(16);
    
        // Add an extra zero to ensure that the result will always be two chars long
        if (result.length < 2) {
            result = "0" + result;
        }
    
        // Return as uppercase, for cosmetic reasons
        return result.toUpperCase();
    }
    

    Usage:

    var LAST_DIGITS = 0x000000A7;
    var MID_DIGITS = 0x00000E00;
    
    var a = GetHex(LAST_DIGITS, 0);
    var b = GetHex(MID_DIGITS, 2); // offset of 2 hex-digits, looking from the right
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to encode DNS protocol header using C and create a UDP datagram.
I want to encode and decode Bitmap object in string base64 . I use
I want to encode binary file into base64 and put it into php page
As the title mentioned, I want to encode a Image Obj into some kind
In my java app I'm preventing XSS attacks. I want to encode URL and
I want to do encode the data before saving it to a database table
I want to use the Html.Encode by replacing Name <%=Html.TextBox(Name, Model.projectModel.Name)%> However, since i`m
I want to do what's described in question 724043 , namely encode the path
I have a multidimensional array, here: $noticeDate = json_encode( $noticesDates ); and I want
I have a big php code that i want to encode and decode it

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.