Ultra-short simplified hexadecimal conversion (Binary/decimal/hexadecimal)

Source: Internet
Author: User
Tags decimal to binary
// Hexadecimal (s) --> decimal (I) [rewrite: jey]
Function hextoint (S: string): integer;
Begin // $ indicates hexadecimal
Result: = strtoint ('$' + S );
End;

// Convert decimal to binary string [rewrite: jey]
Function inttobin (I: integer): string;
Begin
While I <> 0 do
Begin // I mod 2 modulo and format it with format
Result: = format ('% d' + result, [I mod 2]);
I: = I Div 2
End
End;

// Binary (s) --> decimal (d) [rewrite: jey]
Uses math;
Function hextoint (S: string): Double;
Begin
While length (s) <> 0 do
Begin // 2 ^ (length-1) Power
If s [1] = '1' then result: = Result + power (2, length (S)-1 );
S: = copy (S, 2, length (s ));
End
End;

// Decimal (I) --> hexadecimal (s)
// D built-in function, digits length, generally set to 4.
Function inttohex (value: integer; digits: integer): string;

// Data (s) --> binary (s)
// Any data is stored in binary format! (Transfer)
Function conertde (S: string): string;
VaR
I: integer;
Begin
For I: = 1 to length (s) do
Result: = result + inttohex (ord (s [I]), 2 );
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.