• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

From Byte[] to Ascii text String

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a byte array created from an ASCII/HEX string and I have the ability to pull out a bunch of bits through bit shifting, and up till recently I was storing these values in a Long variable.

However When it comes to taking these values and storing them in a string and printing them to some kind of Output as ASCII/HEX I am lost.

So recap. I have a byte array and I pull out any number of bits. I want to then print out these bits in an ASCII format.

I tried this multipl ways, nothing is doing what I need it to do, and frankly I think I am going about this wrong..

I have posted a question similar to this, but it was only about going from a Long to ASCII string, which I know now is not long enough in some cases.

Thank you everyone.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not give us an example of the contents of the byte array; this will make it easier to tell you what to do.
 
Hosh Nasi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, the byte array is just filled with some random Ascii/Hex string.



at this point I would want to perform some bit manipulation to pull out some bits that start at bit five and are a size of 8.

so from the string "Random Message #05" or the Binary value of

0101001001100001011
0111001100100011011
1101101101001000000
1001101011001010111
0011011100110110000
1011001110110010100
1000000010001100110
00000110101

pull out = 01001100

and put it into some variable then print it out in Ascii in this example print out "L". The trouble is the size of the pulled out bits needs to be Dynamic. So I can't use a long like I was before, and I am not sure how to do it in a String. I am not even sure I need a Byte array. I just used it because it made my work with other datatypes eassier

Thanks!
[ September 30, 2004: Message edited by: Hosh Nasi ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic