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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:01:25+00:00 2026-06-02T10:01:25+00:00

I am facing very strange problem in which I have byte[] and when I

  • 0

I am facing very strange problem in which I have byte[] and when I am passing this to Convert.UTF8.GetString(byte[] bytes) method, the system encoding is messing with my bytes and replacing only few special bytes (which I am using as Markers in my system) to some three char string representation.

[0] 70  byte
[1] 49  byte
[2] 45  byte
[3] 86  byte
[4] 49  byte
[5] 253 byte     <-- Special byte
[6] 70  byte
[7] 49  byte
[8] 45  byte
[9] 86  byte
[10]50  byte
[11]253 byte     <-- Special byte
[12]70  byte
[13]49  byte
[14]45  byte
[15]86  byte
[16]51  byte

When I am passing above byte[] into Encoding.UTF8.GetString(bytes) method I am getting following output;

private Encoding _encoding = System.Text.Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback("?"), new DecoderReplacementFallback("?"));       
_encoding.GetString(bytes)  "F1-V1�F1-V2�F1-V3" string

Actual value should not have ‘�’ as this means it failed to encode and replaced those special bytes with ‘�’. Is there anyway I can get around this i.e. convert to string and keep the special bytes representation to a single char.

I have following special bytes which I am trying to use as markers;

byte AM = (byte) 254
byte VM = (byte) 253
byte SM = (byte) 252 

Your help and comments will be appreciated.

Thanks,

—

Sheeraz

  • 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-02T10:01:30+00:00Added an answer on June 2, 2026 at 10:01 am

    The data is only UTF-8 between the markers, so if it were me I would be extracting the delimited portions first, and then UTF-8 decode each portion separately, i.e. read through the byte[] looking for the markers in your binary data, giving you 3 binary chunks (70,49,45,86,49; 70,49,45,86,50; 70,59,45,86,51) which are then decoded into 3 strings. You can’t UTF-8 decode the entire binary sequence because it is not valid UTF-8.

    However, personally, I would say that using a delimiter is dangerous here; I would probably go for a length-prefix approach, so that

    • I know that I’m not accidentally conflating delimiters and real data
    • I can process it more efficiently than byte-by-byte

    For example, if we used a “varint” length prefix, that would be:

    05,70,49,45,86,49,05,70,49,45,86,50,05,70,59,45,86,51
    

    where the 05 is the “varint” length which we interpret as 5 bytes; this means we can process nicely:

    // pseude code
    while(!EOF) {
        int len = ReadVarint();
        var blob = ReadBytes(len);
        string s = Utf8Decode(blob);
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a very strange problem with editingStyleForRowAtIndexPath method. I am planing to
I am facing a very strange problem. I have a grid and when i
I am facing a strange behavior by CakePHP 2.1: I have a method, $this->Time->getTime();
Good morning, I´m facing a very strange problem on which I haven´t found a
I am facing this very weird problem, I have created a custom UITableViewCell on
I am facing very strange problem. After debugging from my side, I thought to
I am facing a very strange problem where the same loop keeps giving me
I'm facing a apparently very strange problem (I must be doing something wrong, just
I am facing a very strange issue. I have a SharePoint webpart that displays
I have an upload system ready, however I might be facing a very high

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.