The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
naming variables with variables Allasso Shell Programming and Scripting 2 06-27-2008 11:45 AM
using variables in sed bishweshwar UNIX for Advanced & Expert Users 1 06-07-2007 09:47 AM
Passing variables to sql from batch shell in linux rama71 Linux 2 06-28-2005 04:38 PM
Using Variables to Set Other Variables superdelic UNIX for Dummies Questions & Answers 3 04-21-2005 11:44 AM
how to set up linux environment variables? dell9 UNIX for Dummies Questions & Answers 5 04-30-2003 05:44 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-04-2008
ritesh_163 ritesh_163 is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 2
Question How to convert byteArray variables to HexaString variables for Linux?

Hello everybody,
I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given below:

Code:
//value in "byte in[] " stores dynamically..
                                byte ch = 0x00;
  int i = 0;
  if (in == null || in.length <= 0) {
   return null;
  }
  String pseudo[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
    "A", "B", "C", "D", "E", "F" };
  StringBuffer out = new StringBuffer(in.length * 2);
  while (i < in.length) {
   ch = (byte) (in[i] & 0xF0); // Strip off high nibble
   ch = (byte) (ch >>> 4);
   // shift the bits down
   ch = (byte) (ch & 0x0F);
   // must do this is high order bit is on!
   out.append(pseudo[(int) ch]); // convert the nibble to a String
   // Character
   ch = (byte) (in[i] & 0x0F); // Strip off low nibble
   out.append(pseudo[(int) ch]); // convert the nibble to a String
   // Character
   i++;
  }
  String rslt = new String(out);
  System.out.println("Hexa Value Buffer:"+out);

Quote:
In Windows:
Hexa Values:B0B0800146018000000000000000002C
total lenth of above hexa value:32

In Linux:
Hexa Value Buffer:EFBFBDEFBFBDEFBFBD014200EFBFBD000000000000000020
total lenth of above hexa value:48
I want the same value in the variable out(String) for both Linux and Windows. For example, if I kept same value for variable byte in[], then user made function in Windows and Linux will store different values in out String. Why is that?

I want the same value of Hexa in Linux also. How is it possible?
Can anybody tell me, what changes should be made in above code so that it works in Linux...
Thank you.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0