Original Post
How do you convert a number into binary form in c++?
// Function IntToBinary takes a byte (unsigned 8-bit int) and returns a string
function IntToBinary(YourInteger : Byte): String;
begin
case (YourInteger) of
// Hex notation in Delphi is done with a $ sign before the number
// Result is equivalant to C++''s "return" statement
$0 : Result := Result + ''0000'';
$1 : Result := Result + ''0001'';
$2 : Result := Result + ''0010'';
$3 : Result := Result + ''0011'';
$4 : Result := Result + ''0100'';
$5 : Result := Result + ''0101'';
$6 : Result := Result + ''0110'';
$7 : Result := Result + ''0111'';
$8 : Result := Result + ''1000'';
$9 : Result := Result + ''1001'';
$A : Result := Result + ''1010'';
$B : Result := Result + ''1011'';
$C : Result := Result + ''1100'';
$D : Result := Result + ''1101'';
$E : Result := Result + ''1110'';
$F : Result := Result + ''1111'';
end;
end;
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more