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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:33:30+00:00 2026-06-18T12:33:30+00:00

I would like to convert integers to bytes. I have an example in Actionscript

  • 0

I would like to convert integers to bytes. I have an example in Actionscript and I need to convert it to Java. For the sake of simplicity let’s assume only one number, 1234. This is my Java code:

int[] a = {1234};
ByteBuffer byteBuffer = ByteBuffer.allocate(a.length * 4);
IntBuffer intBuffer = byteBuffer.asIntBuffer();
intBuffer.put(a);
byte[] array = byteBuffer.array();
for (int i=0; i < array.length; i++) {
    Log.i(T, i + ": " + array[i]);
}

This gives me the following result:

0 : 0
1 : 0
2 : 4
3 : -46

While in Actionscript I have this:

var c:ByteArray = new ByteArray;
c.writeInt(1234);
for(var p:uint=0; p<c.length; p++) {
    trace(p+" : "+c[p]);
}

And the result:

0 : 0
1 : 0
2 : 4
3 : 210

What am I doing wrong, why is the result different? Thanks!

  • 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-18T12:33:31+00:00Added an answer on June 18, 2026 at 12:33 pm

    Java uses unsigned bytes.

    ActionScript probably signed by default.

    3 : -46 //signed
    3 : 210 //unsigned
    

    This can print every byte as unsigned:

    System.out.println((b < 0 ? 256 + b : b));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with my code. I would like to write only numbers/integers in
I have a list of integers that I would like to convert to one
Motivation: I would like to convert hashes (MD5/SHA1 etc) into decimal integers for the
I have a vector<int> container that has integers (e.g. {1,2,3,4}) and I would like
I would like to convert an integer array in java, to an Inputstream, after
I would like to import some basic data (only few integers) from an Excel
I have the following query in SQL which I would like to convert to
I would like to convert a java.net.InetAddress and I fight with the signed /
I would like convert the below text into a nested array, something like you
I would like to convert numbers to the shorter form using NSNumberFormatter . For

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.