473,385 Members | 1,320 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,385 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];  
  13.  
  14.  
  15.     }
  16.     return con;
  17. }
Aug 10 '09 #1
5 11367
JosAH
11,448 Expert 8TB
@Elaine121
What are the exact rules for your en/decoding? i.e. when do you add an 'e' or an 'f'?

kind regards,

Jos
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
JosAH
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,

Jos
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

2
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...
4
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...
13
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...
6
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)...
8
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,...
16
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...
4
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,...
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...
2
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...
10
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
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...
0
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.