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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:51:03+00:00 2026-06-16T18:51:03+00:00

I have one String like 01030920316 . when i am going to convert this

  • 0

I have one String like "01030920316".
when i am going to convert this string in long and then convert in bytes then its given below output for java

output in java : Tag in bytes :  0, 0, 0, 0, 61, 114, -104, 124

same thing i do in C when i get this output

output in C : Tag in bytes : 124,152,114,61,0,0,0,0

Here I understand the different between -104 and 152 because of signed and unsigned but why 0’s at first in java and in C at last. for this behavior i am getting problem when my this bytes goes to C program side for verification.

Please explain me the where problem occurs.

Java program :

final byte[] tagBytes = ByteBuffer.allocate(8)
                .putLong(Long.parseLong("01030920316")).array();
System.out.println("Tag in bytes  >> " + Arrays.toString(tagBytes));

C program :

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

/** To access long long values as a byte array*/
typedef union uInt64ToByte__
{
    uint64_t m_Value;
    unsigned char m_ByteArray[8];

}uInt64ToByte;

int main()
{
    uInt64ToByte longLongToByteArrayUnion;
    longLongToByteArrayUnion.m_Value = atoll("01030920316");
    printf("%d,%d,%d,%d,%d,%d,%d,%d",longLongToByteArrayUnion.m_ByteArray[0],longLongToByteArrayUnion.m_ByteArray[1],longLongToByteArrayUnion.m_ByteArray[2],longLongToByteArrayUnion.m_ByteArray[3],longLongToByteArrayUnion.m_ByteArray[4],longLongToByteArrayUnion.m_ByteArray[5],longLongToByteArrayUnion.m_ByteArray[6],longLongToByteArrayUnion.m_ByteArray[7]);
    return 0;
}
  • 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-16T18:51:04+00:00Added an answer on June 16, 2026 at 6:51 pm

    Strings are simply differently stored in Java and C. You have to remember that applications written in C are native and Java applications are run in Java Virtual Machine. Java byte code is platform independent and this is why your Java code would act the same on all operating systems / processor architectures. On the other hand the order of stored characters might be different in C (edit: on different architectures)

    Edit2: Let’s say we have a number 109 which is 1101101 binary. Why? 1 * 64 + 1 * 32 + 0 * 16 + 1 * 8 + 1 * 4 + 0 * 2 + 1 * 1 = 109. The most left bit is called “the most significant” because it’s weight is the biggest (2^6 = 64) and the most right bit is called “the least significant” because it’s weight is the smallest (only 1). 109 is quite boring because it can be stored in a single byte. Let’s assume that we have something bigger like: 1000 which is 00000011 11101000 binary. It is stored in two bytes (let’s say X and Y). Now we can save that number as XY (big-endian) or YX (little-endian). In big-endian the first byte (with the lowest address) is the most significant byte. In little-endian the first byte is the least significant byte. x86 is little-endian and JVM is big-endian. This is why the outputs are different.

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

Sidebar

Related Questions

I read have one string like this: $var = '[[tom,10,17.5],[af,13,[x,10,y,12,z,11]]]'; How should I convert
I have a string like this one: 1.1 Apoyar en la planeación y realización
i have a string like this one: $string = some text http://dvz.local/index/index/regionId/28 http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
i have a string like this one $sitesinfo = 'site 1 titles-example1.com/ site 2
Suppose I have a string like this: one two three four five six seven
I have a class like the one below: class Foo { private: std::map<std::string, Bar*>
I have a string array like this. string[] queries with data more than one
I have one string like this 2012 12 12 12:12, how to format as
I have one large string which goes like this: $string = '<span id=nothread307693965>blabla here
I have one string, that looks like this: a[abcdefghi,2,3,jklmnopqr] The beginning a is fixed

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.