sting to binairy code

Hello,

I'm making a program that converts a string in to 8 digit binary code.
now i have have the problem that delphi defautls delivers a 32 bits code.
If i want to only use the right 8 digits i use rightstr(result,8)
this delivers a 8 digit code a i want it to be but it are not the most right digits infact it is digit 1 to 9 and not 0 to 8 as i want it to be.
how can i resolve this problem.

I'm also looking for a wat to munipulate the order of the digits in the way I want them to be. So let's say the string that comes out is 10011010 i want to change that in to 00011101. what is the easyest way to do this because this is only on character and it has to be done with a comple string.

kind regards,

P675

Comments

  • : Hello,
    :
    : I'm making a program that converts a string in to 8 digit binary
    : code.
    : now i have have the problem that delphi defautls delivers a 32 bits
    : code.
    : If i want to only use the right 8 digits i use rightstr(result,8)
    : this delivers a 8 digit code a i want it to be but it are not the
    : most right digits infact it is digit 1 to 9 and not 0 to 8 as i want
    : it to be.
    : how can i resolve this problem.
    :
    : I'm also looking for a wat to munipulate the order of the digits in
    : the way I want them to be. So let's say the string that comes out is
    : 10011010 i want to change that in to 00011101. what is the easyest
    : way to do this because this is only on character and it has to be
    : done with a comple string.
    :
    : kind regards,
    :
    : P675

    If I understand you correctly you want to change each individual character ASCII code of a string into its binary representation. Here's an example which does that:
    [code]
    Result := '';
    for i := 1 to length(text) do
    begin
    Result := Result + FastIntToBin(byte(text[i]), 8) + ' ';
    // FastIntToBin is listed in the CodePedia
    end;
    [/code]
    This code will result in a big-endian (http://en.wikipedia.org/wiki/Endianess) binray representation of the string, with each character separated by a space.

    It is quite simple to reverse a string. All it takes is a for-loop and some playful indexing (remember a string is an array of char). Hint: copy the string into a new string 1 character at a time, starting with the last character and ending with the first.
  • : : Hello,
    : :
    : : I'm making a program that converts a string in to 8 digit binary
    : : code.
    : : now i have have the problem that delphi defautls delivers a 32 bits
    : : code.
    : : If i want to only use the right 8 digits i use rightstr(result,8)
    : : this delivers a 8 digit code a i want it to be but it are not the
    : : most right digits infact it is digit 1 to 9 and not 0 to 8 as i want
    : : it to be.
    : : how can i resolve this problem.
    : :
    : : I'm also looking for a wat to munipulate the order of the digits in
    : : the way I want them to be. So let's say the string that comes out is
    : : 10011010 i want to change that in to 00011101. what is the easyest
    : : way to do this because this is only on character and it has to be
    : : done with a comple string.
    : :
    : : kind regards,
    : :
    : : P675
    :
    : If I understand you correctly you want to change each individual
    : character ASCII code of a string into its binary representation.
    : Here's an example which does that:
    : [code]:
    : Result := '';
    : for i := 1 to length(text) do
    : begin
    : Result := Result + FastIntToBin(byte(text[i]), 8) + ' ';
    : // FastIntToBin is listed in the CodePedia
    : end;
    : [/code]:
    : This code will result in a big-endian
    : (http://en.wikipedia.org/wiki/Endianess) binray representation of
    : the string, with each character separated by a space.
    :
    : It is quite simple to reverse a string. All it takes is a for-loop
    : and some playful indexing (remember a string is an array of char).
    : Hint: copy the string into a new string 1 character at a time,
    : starting with the last character and ending with the first.

    Thanks for the intttobin code. it works fine.
    Now I have the problem that I can't find the right place to change de digits. The problem I have here is that if I put in a complete sting. lets say ABCD every character now is 8 digits but i have to re-arange them every 16 digits. So if AB gives me 01000001 01000010 and CD gives me 01000011 01000100 is will be in one line but I have to change the order of AB seperated from CD in the same way. So the left 0 of AB becomes the 4 of the left and de 1 after the becomes the 15 left. And with CD also the left 0 of AB becomes the 4 of the left and de 1 after the becomes the 15 left.

    Could some help me with this.

    Kind regards,

    P675
  • : : : Hello,
    : : :
    : : : I'm making a program that converts a string in to 8 digit binary
    : : : code.
    : : : now i have have the problem that delphi defautls delivers a 32 bits
    : : : code.
    : : : If i want to only use the right 8 digits i use rightstr(result,8)
    : : : this delivers a 8 digit code a i want it to be but it are not the
    : : : most right digits infact it is digit 1 to 9 and not 0 to 8 as i want
    : : : it to be.
    : : : how can i resolve this problem.
    : : :
    : : : I'm also looking for a wat to munipulate the order of the digits in
    : : : the way I want them to be. So let's say the string that comes out is
    : : : 10011010 i want to change that in to 00011101. what is the easyest
    : : : way to do this because this is only on character and it has to be
    : : : done with a comple string.
    : : :
    : : : kind regards,
    : : :
    : : : P675
    : :
    : : If I understand you correctly you want to change each individual
    : : character ASCII code of a string into its binary representation.
    : : Here's an example which does that:
    : : [code]: :
    : : Result := '';
    : : for i := 1 to length(text) do
    : : begin
    : : Result := Result + FastIntToBin(byte(text[i]), 8) + ' ';
    : : // FastIntToBin is listed in the CodePedia
    : : end;
    : : [/code]: :
    : : This code will result in a big-endian
    : : (http://en.wikipedia.org/wiki/Endianess) binray representation of
    : : the string, with each character separated by a space.
    : :
    : : It is quite simple to reverse a string. All it takes is a for-loop
    : : and some playful indexing (remember a string is an array of char).
    : : Hint: copy the string into a new string 1 character at a time,
    : : starting with the last character and ending with the first.
    :
    : Thanks for the intttobin code. it works fine.
    : Now I have the problem that I can't find the right place to change
    : de digits. The problem I have here is that if I put in a complete
    : sting. lets say ABCD every character now is 8 digits but i have to
    : re-arange them every 16 digits. So if AB gives me 01000001 01000010
    : and CD gives me 01000011 01000100 is will be in one line but I have
    : to change the order of AB seperated from CD in the same way. So the
    : left 0 of AB becomes the 4 of the left and de 1 after the becomes
    : the 15 left. And with CD also the left 0 of AB becomes the 4 of the
    : left and de 1 after the becomes the 15 left.
    :
    : Could some help me with this.
    :
    : Kind regards,
    :
    : P675
    :
    As I've hinted at previously, this is a simple for loop and some creative indexing. Here's an example:
    [code]
    function ReverseString(s: string): string;
    var
    i: integer;
    begin
    Result := '';
    for i := 1 to Length(s) do
    Result := s[i]+ Result;
    end;
    [/code]
    This function wil reverse the string ABCDEFG to GFEDCBA.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion