Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
e12cb143
Commit
e12cb143
authored
Mar 09, 2011
by
antirez
Browse files
endianess conversion API, to be applied to specially encoded data types for arch agnostic encoding.
parent
b1a8e3e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/endian.c
0 → 100644
View file @
e12cb143
/* Toggle the 16 bit unsigned integer pointed by *p from little endian to
* big endian */
void
memrev16
(
void
*
p
)
{
unsigned
char
*
x
=
p
,
t
;
t
=
x
[
0
];
x
[
0
]
=
x
[
1
];
x
[
1
]
=
t
;
}
/* Toggle the 32 bit unsigned integer pointed by *p from little endian to
* big endian */
void
memrev32
(
void
*
p
)
{
unsigned
char
*
x
=
p
,
t
;
t
=
x
[
0
];
x
[
0
]
=
x
[
3
];
x
[
3
]
=
t
;
t
=
x
[
1
];
x
[
1
]
=
x
[
2
];
x
[
2
]
=
t
;
}
/* Toggle the 64 bit unsigned integer pointed by *p from little endian to
* big endian */
void
memrev64
(
void
*
p
)
{
unsigned
char
*
x
=
p
,
t
;
t
=
x
[
0
];
x
[
0
]
=
x
[
7
];
x
[
7
]
=
t
;
t
=
x
[
1
];
x
[
1
]
=
x
[
6
];
x
[
6
]
=
t
;
t
=
x
[
2
];
x
[
2
]
=
x
[
5
];
x
[
5
]
=
t
;
t
=
x
[
3
];
x
[
3
]
=
x
[
4
];
x
[
4
]
=
t
;
}
#ifdef TESTMAIN
#include <stdio.h>
int
main
(
void
)
{
char
buf
[
32
];
sprintf
(
buf
,
"ciaoroma"
);
memrev16
(
buf
);
printf
(
"%s
\n
"
,
buf
);
sprintf
(
buf
,
"ciaoroma"
);
memrev32
(
buf
);
printf
(
"%s
\n
"
,
buf
);
sprintf
(
buf
,
"ciaoroma"
);
memrev64
(
buf
);
printf
(
"%s
\n
"
,
buf
);
return
0
;
}
#endif
src/endian.h
0 → 100644
View file @
e12cb143
#ifndef __ENDIAN_H
#define __ENDIAN_H
void
memrev16
(
void
*
p
);
void
memrev32
(
void
*
p
);
void
memrev64
(
void
*
p
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment