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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:47:40+00:00 2026-05-22T00:47:40+00:00

I am trying to write an Integer from C# and read it from Java.

  • 0

I am trying to write an Integer from C# and read it from Java. An integer is 4 bytes in both languages. However when I write it from C#, integer 1 is written in the following bytes
1000. Meaning the first byte is 1 and the rest is 0.

But in Java the same thing is written as 0001. Meaing the first 3 bytes are 0 and the last is 1.

Is there a simple way of reading and writing among these languages instead of manually reversing every 4 byte?
The code for Java

ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.putInt(1);

for(byte b: buffer.array()){
      System.out.print(b);
}

The code for C#

MemoryStream ms = new MemoryStream();
using(BinaryWriter writer = new BinaryWriter(ms))
{
    writer.Write((int)1);

}
foreach(byte b in ms.ToArray()){
    Console.Write(b);
}
  • 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-22T00:47:41+00:00Added an answer on May 22, 2026 at 12:47 am

    As this post points aus http://kirkwylie.blogspot.com/2008/11/c-binarywriter-is-little-endian-because.html C# BinaryWriter supports only little endian so you have to configure it on the java site with the order method http://download.oracle.com/javase/1.4.2/docs/api/java/nio/ByteBuffer.html#order%28java.nio.ByteOrder%29

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

Sidebar

Related Questions

I'm trying to write a bitmap (.bmp) parser/reader by reading raw bytes from the
im trying to write an app that will display a list off lines from
I am trying to send an image from a Java desktop application to a
I am trying to read and write values in registry. I get return something
I'm trying to read user input of integer. (like cin >> nInput; in C++)
I'm trying to read a remote binary file (say, image) from internet like this:
I'm trying to write binary data files from fortran, but I find the regular
Im trying to read in image file from a server , with the code
I am trying to write a select query from one single table in SQLite
I'm trying to write a windows phone 7 app which reads from an xml

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.