473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert integer to hex in little endien format

4
Please tell me...
how to convert integer to hex in little endian format ?

example : i'm input int = 9995
then
the output in Array String is [0b,27,00,00]
Oct 7 '09 #1
6 10534
r035198x
13,262 8TB
What have you done so far?
Oct 7 '09 #2
ngajay
4
until now i'm using bytebuffer but i can't view the result
my code is

ByteBuffer bb = ByteBuffer.allocate(4);
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.putInt(9995);
System.out.println("x = "+ bb.toString());

i no have idea to print the bb..
Oct 7 '09 #3
r035198x
13,262 8TB
Did you want to make the println

Expand|Select|Wrap|Line Numbers
  1. System.out.println("x = " + Arrays.toString(bb.array()));
instead?
Oct 7 '09 #4
ngajay
4
thanks that's work for me...
but the result is in decimal...
can you give me a hint how to get the result in hex like [0b,27,00,00]

i try code like this
Expand|Select|Wrap|Line Numbers
  1.         ByteBuffer  bb = ByteBuffer.allocate(4);
  2.         bb.order(ByteOrder.LITTLE_ENDIAN);
  3.         bb.putInt(9995);
  4.         //bb.putInt(43690);
  5.         String xx = Arrays.toString(bb.array());
  6.  
  7.         String yy;
  8.         yy = xx.substring(1,3);
  9.         int i = Integer.parseInt(yy);
  10.         String hex1 = Integer.toHexString(i);
  11.         System.out.println("Hexa : " + hex1);
the result is "Hexa : b" not "Hexa : 0B"

the code has problem when put integer 43690(0xAAAA in hex) the result in array is [-86, -86, 0, 0] -86 when convert in java the result is ffffffAA not AA

would you help me againt :)
Oct 7 '09 #5
r035198x
13,262 8TB
You want to try something like
Expand|Select|Wrap|Line Numbers
  1. System.out.print("x = ");
  2. for (byte b : bb.array()) {
  3.     System.out.printf("%2s", Integer.toHexString(b) + " ");
  4. }
  5.  
Read all about those formatters in the API specs for the Fomatter class.
Oct 7 '09 #6
ngajay
4
very2 works thanks...
Oct 7 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
43
by: Steven T. Hatton | last post by:
http://public.research.att.com/~bs/bs_faq2.html#int-to-string Is there no C library function that will take an int and convert it to its ascii representation? The example Bjarne shows in his faq...
8
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
7
by: WorldIsEnding | last post by:
Hey, Im having trouble with converting a Numeric value (such as a single digit number like 1 or 5) into a time format. I need to convert a number entered into a variable into Hours on the...
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
10
by: cmdolcet69 | last post by:
Public ArrList As New ArrayList Public bitvalue As Byte() Public Sub addvalues() Dim index As Integer ArrList.Add(100) ArrList.Add(200) ArrList.Add(300) ArrList.Add(400) ArrList.Add(500)
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.