Binary Representation of Decimal Numbers
Binary Representation of Decimal Numbers
Description
This example shows how to convert a decimal number into a
AnsiString that holds its binary representation.
For example the number 15 will be converted into
the AnsiString: "00001111". The decimal number 1000 into
"001111101000". The decimal number 1048576 into:
"000100000000000000000000", etc.
This approach uses the IntToHex() function to convert decimal
numbers (integers) to hexadecimal numbers and a std::map to
convert hexadecimal numbers into strings
(binary representation).
The two step conversion is done by the following function:
String DecimalToBinaryStr(int DecimalNumber);
which takes a decimal number as a parameter and returns
an AnsiString containing the binary representation of that number.
BinaryRepresentation.cpp
#include <vcl.h>
#pragma hdrstop
#include "BinaryRepresentation.h"
#include
Homepage
Copyright © 1997-2002 Rodolfo A. Frino. All rights reserved.