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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:28:58+00:00 2026-06-03T18:28:58+00:00

EDIT: Ooooops. console.log (Buffer.byteLength (, utf8)); //–> 3 I want to count the number

  • 0

EDIT: Ooooops.

console.log (Buffer.byteLength ("", "utf8")); //--> 3

I want to count the number of bytes of a character. This is what I have:

var charBytesLength = function (c){
    var n = 0;
    c = c.charCodeAt (0);
    do{
        c = c >>> 8;
        n++;
    }while (c);
    return n;
};

If the character is encoded using UTF8, for characters with more than 2 bytes the function always returns 2 because in Javascript a character is a 16-bit value and charCodeAt() only returns the value between 0 and 65535.

For example:

"".charCodeAt (0)

returns 65533, when the real hexadecimal value is 0x24065 (147557 in decimal)

Do you know how to count the real number of bytes?

  • 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-03T18:28:58+00:00Added an answer on June 3, 2026 at 6:28 pm
    console.log (Buffer.byteLength ("", "utf8")); //--> 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: The below question was answered by this . I have a new updated
Edit: I have solved this by myself. See my answer below I have set
EDIT: I think I've worked something out. - This character - ’ - seems
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
EDIT: There's now a doc page on this so this question is irrelevant, also
edit alright, I guess C is painful in nature--Just, this part, is particularly painful.
Edit: I'm looking for solution for this question now also with other programming languages.
EDIT: Changed as I have a different issue with the same code 2nd Edit:
EDIT Leaving this for posterity, but nearly a year later, to get down voted,
EDIT After staring at this for 2 days, I do see one issue. I

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.