Transform 10 credit integer to a 16-way string

zhaozj2021-02-16  47

Since there is always someone asks how to ask 10 to the number of items, convert to a 16-way string,

Considering that someone will continue to ask, so there is a method here for reference only :)

If you are not right, please bear with me.

#include #include

Void main () {{0; cout << "Enter Interger to change:"; cin >> ix; long iy = 0; int A1 = 0; A1 = (ix & 0x000000FF); // Extract the highest bit byte int A2 = 0; A2 = (IX & 0x0000FF00) >> 8; INT A3 = 0; A3 = (IX & 0x00FF0000) >> 16; INT A4 = 0; A4 = (IX & 0xFF000000) >> 24; // Extract the lowest bit byte

Char buffer [10];

Sprintf (Buffer, "%. 2X% .2x% .2x% .2x", A4, A3, A2, A1); Printf ("OUTPUT: / N% S / N", Buffer;

Enter Interger to Change: 16909060Output: 01020304press any key to continche

F: /> center interger to change: 2500output: 000009C4

Thank you very much :), because the string with a char store can cause overflow, so error results are now corrected.

转载请注明原文地址:https://www.9cbs.com/read-25905.html

New Post(0)