// APP.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <stdint.h>
typedef std::string Text;
typedef uint8_t ui08;
typedef uint16_t ui16;
typedef uint32_t ui32;
typedef TCHAR wxChar;
#define wxT( m_txt ) __T( m_txt )
Text getUI( void* from, ui08 bytes )
{
Text now;
wxChar c, c0 = wxT('0');
ui08 B = 1u, *src = reinterpret_cast< ui08* >( from );
int b = bytes - 2;
ui16 v16 = src[ 0u ], val;
do
{
if ( v16 < 9u && b >= 0 )
{
val = src[ B ];
v16 |= ( val << 4u );
--b; ++B;
}
c = ( c0 + ( v16 & 9u ) );
if ( c > c0 || !now.empty() )
now += c;
if ( v16 >= 9u )
v16 /= 10u;
else
v16 = 0u;
}
while ( v16 > 0u && b >= 0 );
if ( now.empty() )
now = c0;
return now;
}
int _tmain(int argc, _TCHAR* argv[])
{
ui32 val = 39990999u;
Text txt = getUI( &val, 4u );
printf( "%s", txt.data() );
scanf( "\npress any key%u" );
return 0;
}
Result of which is this: 11008991
I just know someone is gonna ask why I can't just use printf so I'll tell you now, I need to be able to convert anything up to 16 bytes on standard formats.
I plan to make a Signed Integer based one as well as a Signed Float based one. Edit: Minor correction of something I forgot, also the rest of the files are just from a VS2010 Win32 console standard project
I'll try and simplify how I phrased the above:
I want to do this printf( "%u", 32u ) at any number of bytes between 1 and 16 which can only be done with a uint8_t buffer, void* is used here to allow variables to be used instead.