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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:48:14+00:00 2026-06-19T02:48:14+00:00

I am converting code that works in Java but not in C# byte[] buffer

  • 0

I am converting code that works in Java but not in C#

byte[] buffer = new byte[64];
this.buffer[((int)this.count & 0x3F)] = -128;

This generates a compile time error “Constant value ‘-128’ cannot be converted to a ‘byte’.” How can I store a negative number for a byte?

  • 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-19T02:48:15+00:00Added an answer on June 19, 2026 at 2:48 am

    The byte data type in Java is signed (-128–127). The equivalent data type in C# is sbyte.

    So the equivalent C# code is as follows:

    sbyte[] buffer = new sbyte[64];
    buffer[..] = -128;
    

    If you want an array of unsigned bytes (0–255), the byte with the same bit pattern as the sbyte -128 is 128 (0x80).

    byte[] buffer = new byte[64];
    buffer[..] = 128;
    

    See also: Integral Types Table (C# Reference)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that I'm converting from Perl to Java. It makes pretty
I've got some C# code that I'm converting to Objective-C. In C# I would
I am manually converting code from Java (1.6) to C# and finding some difficulty
I'm converting a code from C to Delphi, but I'm stuck on the last
How do I prevent Cyclone from converting the code? I mean, I want this
Could you please help me converting this c++ code into python: I am trying
i'm converting a c++ header to java and the following does not work. opstring
I'm converting java jUnit tests to scala. As scala does not use checked exceptions
I'm converting someone else's java code to scala (for the curious, it's the example
I have the following code in Java: float in[][] = new float[2][2]; float B[]

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.