Hexadecimal byte operations

Source: Internet
Author: User

// There is a space between the nth byte value of the hexadecimal string
Function agetbyteat (hexvalue: string; N: integer): string;
Begin
Result: = copy (hexvalue, (n-1) * 3 + );
End;

 

// The hexadecimal string starts from n Bytes and has a space between M bytes.
Function agethexsubstr (hexvalue: string; n, m: integer): string;
VaR
I: integer;
Temp: string;
Begin
Temp: = '';
For I: = n to N + M-1 do
Temp: = temp + agetbyteat (hexvalue, I );
Result: = temp;
End;

 

// Convert a hexadecimal string to a string
Function hexstrtostra (S: string): string;
VaR
T: integer;
TS: string;
M, code: integer;
Begin
T: = 1;
Result: = '';
While T <= length (s) do
Begin
While (T <= length (s) and (not (s [T] in ['0 '.. '9', 'A '.. 'F', 'A '.. 'F']) Do
INC (t );
If (t + 1> length (s) or (not (s [t + 1] in ['0 '.. '9', 'A '.. 'F', 'A '.. 'F']) then
TS: = '$' + s [T]
Else
TS: = '$' + s [T] + s [t + 1];
Val (TS, M, Code );
If code = 0 then
Result: = Result + CHR (m );
INC (T, 2 );
End;
End;

 

// Convert a string to a hexadecimal string
Function strtohexstra (S: string): string;
VaR
I: integer;
Begin
For I: = 1 to length (s) do
Begin
If I = 1 then
Result: = inttohex (ord (s [1]), 2)
Else result: = Result + ''+ inttohex (ord (s [I]), 2 );
End;
End;

 

// Add spaces between bytes
Function addspacesep (const S: string): string;
VaR
I: integer;
Begin
Result: = '';
For I: = 1 to length (s) do
Begin
Result: = Result + s [I];
If I mod 2 = 0 then
Result: = Result + '';
End;
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.