/////////////////////////////////////////////////////////////////////////////// // // (c) Digi International Inc. 2002. All Rights Reserved // // Digi provides this document "as is," without warranty of any kind, // either expressed or implied, including, but not limited to, the implied // warranties of fitness or merchantability for a particular purpose. Digi // may make improvements and/or changes in this document or in the product(s) // and/or the program(s) described in this document at any time. // // This document could include technical inaccuracies or typographical errors. // Changes are periodically made to the information herein; these changes may // be incorporated in new editions of the publication. // // Digi International Inc. // 11001 Bren Road East // Minnetonka, MN 55343, USA // Tel: +1 (952) 912-3444 // Fax: +1 (952) 912-4952 // http://www.digi.com/ // /////////////////////////////////////////////////////////////////////////////// // HexDumpData.cpp : // #include "stdafx.h" //--------------------------------------------------------------------------- // // HexDumpData // // Description: // // Utitily function for dumping data in a human readable hex format to // stdout. // // Parameters: // // Data - Pointer to contiguous byte array of data // Length - Number of bytes Data points to // // Return Value: // // Remarks: // // This function assumes that Data is a valid pointer to at least // Length number of bytes. // //--------------------------------------------------------------------------- void HexDumpData(BYTE const * const Data, DWORD const Length) { char HexString[25] = {0}; char CharString[9] = {0}; for (DWORD i = 0; i < Length; i++) { BYTE Datum = Data[i]; char FormatString[4]; sprintf(FormatString, "%.2x ", Datum); strcat(HexString, FormatString); sprintf(FormatString, "%c", isprint(Datum) ? Datum : '.'); strcat(CharString, FormatString); DWORD NextIndex = (i + 1); if ((NextIndex % 8 == 0) || (NextIndex == Length)) { printf("%-26.26s%s\n", HexString, CharString); HexString[0] = '\0'; CharString[0] = '\0'; } } }