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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:05:18+00:00 2026-05-15T22:05:18+00:00

I was wondering why both utf-16le and utf-16be exists? Is it considered to be

  • 0

I was wondering why both utf-16le and utf-16be exists? Is it considered to be “inefficient” for a big-endian environment to process a little-endian data?

Currently, this is what I use while storing 2 bytes var locally:

  unsigned char octets[2];
  short int shotint = 12345; /* (assuming short int = 2 bytes) */
  octets[0] = (shortint) & 255;
  octets[1] = (shortint >> 8) & 255);

I know that while storing and reading as a fixed endianness locally – there is no endian risk. I was wondering if it’s considered to be “inefficient”? what would be the most “efficient” way to store a 2 bytes var? (while restricting the data to the environment’s endianness, local use only.)

Thanks, Doori Bar

  • 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-15T22:05:18+00:00Added an answer on May 15, 2026 at 10:05 pm

    This allows code to write large amounts of Unicode data to a file without conversion. During loading, you must always check the endianess. If you’re lucky, you need no conversion. So in 66% of the cases, you need no conversion and only on 33% you must convert.

    In memory, you can then access the data using the native datatypes of your CPU which allows for efficient processing.

    That way, everyone can be as happy as possible.

    So in your case, you need to check the encoding when loading the data but in RAM, you can use an array of short int to process it.

    [EDIT] The fastest way to convert a 16bit value to 2 octets is:

    char octet[2];
    short * prt = (short*)&octet[0];
    *ptr = 12345;
    

    Now you don’t know if octet[0] is the low or upper 8 bits. To find that out, write a know value and then examine it.

    This will give you one of the encodings; the native one of your CPU.

    If you need the other encoding, you can either swap the octets as you write them to a file (i.e. write them octet[1],octet[0]) or your code.

    If you have several octets, you can use 32bit integers to swap two 16bit values at once:

    char octet[4];
    short * prt = (short*)&octet[0];
    *ptr ++ = 12345;
    *ptr ++ = 23456;
    
    int * ptr32 = (int*)&octet[0];
    int val = ((*ptr32 << 8) & 0xff00ff00) || (*ptr >> 8) & 0x00ff00ff);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering given both the native js and jquery event handler, which one should
Two general questions I'm wondering about both in the case for a given file(.js,
These 2 ways of working both work, but I'm wondering if there's a difference
As a newb to jQuery I'm wondering if it's possible to have both jQuery
I've been wondering why do some languages, such as Java run on Both Linux
I'm seeing the command 'pull' and wondering how that's different from a 'clone'. Both
The title pretty much covers it. Wondering if anybody knows this. I'm seeing both
Sometimes $('.classname') and $.find('.classname') gives different result. Wondering what is the difference between both.
I'm wondering if there are any gems out there that support both Rails 2
I was wondering if it is really necessary to validate in both JS and

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.