473,372 Members | 1,045 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,372 software developers and data experts.

byte stuffing

Hi i send characters to a server with escape character 'e' and flag 'f'. But now i dont know how to extract the original string. I thought maybe this method would work but i was wrong. any help plz?

Original String = "ref"
frame = "freeeff"
extracted content must be "ref" again.

Expand|Select|Wrap|Line Numbers
  1. public String content()
  2. {
  3.     char wrd[] = words.toCharArray();
  4.     String con = "";
  5.     for(int i=1; i < (wrd.length-2); i++ )
  6.     {
  7.         if(wrd[i] == 'e'){
  8.         con += wrd[i+1];
  9.         i++;
  10.         }
  11.         else
  12.           con += wrd[i];  
  15.     }
  16.     return con;
  17. }
Aug 10 '09 #1
5 11359
11,448 Expert 8TB
What are the exact rules for your en/decoding? i.e. when do you add an 'e' or an 'f'?

kind regards,

Aug 10 '09 #2
the 'f' is added at the start and end of the string to indicate the beginning and end. if there is an 'f' in the actual string you place an 'e' in front so you will know it is an f and not the end of the string. because an 'e' is used it must also be place in front of any 'e' that is in the original string.

another example: "hello friend" would be: "fheello efrieendf".
Aug 10 '09 #3
11,448 Expert 8TB
Well, as far as I can see your code works; it just stops one character too early: make that loop terminating condition i <= (wrd.length-2) and all should be fine.

kind regards,

Aug 10 '09 #4
the problem i get is instead of displaying "ref" it just displays "r f".
Aug 11 '09 #5
never mind i got it to work. Thanx for the help
Aug 11 '09 #6

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

Similar topics

by: David Cook | last post by:
Java's InetAddress class has some methods that use a byte-array to hold what it describes as a 'raw IP address'. So, I assume that they mean an array like: byte ba = new byte; would hold an...
by: sarath1111 | last post by:
hi, I have to perform BIT STUFFING in C Language. I have to get data from the user and stuff the data and then transmit it. I have to destuff it at the other end. I have very less knowledge of...
by: Ray Z | last post by:
So far, I get the idea that if I want to use both the unmanaged and managed memory, I can not avoid memory copy. But I DO need to avoid it. I get a idea that maybe I could use "union" to convert...
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
by: johannblake | last post by:
I have a variable that is 1 bit wide. I also have a variable that is a byte. I want to shift the bits out of the byte into the bit variable (one at a time) but am not sure how to do this or whether...
by: Frederick Gotham | last post by:
What do you think of the following code for setting and retrieving the value of bytes in an unsigned integer? The least significant bit has index 0, then the next least significant bit has index 1,...
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.