【发布时间】:2018-07-26 15:49:18
【问题描述】:
我需要使用 int 调用 byteSwap(),然后将其转换为十六进制并反转十六进制。前任。 byteSwap(2030) 或 7ee,十六进制应返回 ee7。这个程序还做了一些其他的事情,我想使用 reverse() 在 byteSwap() 中反转。我尝试在 byteSwap() 中使用几个不同的循环,但似乎无法让十六进制值实际反转。
#include <iostream>
#include <array>
using namespace std;
void putInOrder(string *s1, string *s2);
void copy(int *f, int *t, int n);
void reverse(char *x, int n);
int byteSwap(int i);
int main() {
string a = "A";
string z = "Z";
auto *s1 = (string *) "A";
auto *s2 = (string *) "Z";
putInOrder(&z, &a);
int arr1 [3] = {3,4,5};
int arr2 [3] = {6,7,8};
int n;
cout << "Enter a number of values to be copied: ";
cin >> n;
copy(arr1,arr2,n);
char x = 0;
string name = "Computer";
reverse(&name[0],9);
byteSwap(2030);
return 0;
}
void putInOrder(string *s1, string *s2)
{
cout << s1 << " " << s2 << endl;
if(s2 > s1)
{
swap(s1,s2);
}
else if (s1 > s2)
{
cout << s1 << " " << s2 << endl;
}
cout << s1 << " " << s2 << endl;
}
void copy(int *f, int *t, int n)
{
for(int i = 0; i <= n + 2; ++i)
{
t[i+3] = f[i];
cout << t[i] << " ";
}
cout << "\n";
}
void reverse(char *x, int n)
{
for(int i = n - 1; i >=0; --i)
{
cout << x[i] << "";
}
cout << "\n";
}
int byteSwap(int i)
{
}
【问题讨论】:
-
将十进制转换为十六进制不是我的主要问题,因此不是重复的。
-
那么,主要问题是什么?反转十六进制是一个问题。请澄清
-
不清楚你在问什么。你想反转
x指向的char数组吗?值是值,无论是用十进制、八进制、二进制还是十六进制文字表示。 -
2030 是 07ee,所以反过来应该是 ee07 而不是 ee7?
标签: c++ arrays pointers hex reverse