Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverse bytes function #21915

Closed
1 of 2 tasks
kbkpbot opened this issue Jul 23, 2024 · 3 comments
Closed
1 of 2 tasks

reverse bytes function #21915

kbkpbot opened this issue Jul 23, 2024 · 3 comments
Labels
Feature Request This issue is made to request a feature.

Comments

@kbkpbot
Copy link
Contributor

kbkpbot commented Jul 23, 2024

Describe the feature

Need some functions , that can reverse bytes in u128/u64/u32/u16
for example, reverse_u32(0x12345678)=0x78563412

Use Case

This can be used in some encryption/decryption algo.
sometimes , it need reverse a 128bits/64bits...

Proposed Solution

Integrate into encoding.binary?

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V full version: V 0.4.6 6e8124f

Environment details (OS name and version, etc.)

V full version: V 0.4.6 6e8124f
OS: linux, Ubuntu 22.04.4 LTS
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz

getwd: /media/HD/github/lang/v/vlib/encoding/leb128
vexe: /media/HD/github/lang/v/v
vexe mtime: 2024-07-23 07:26:34

vroot: OK, value: /media/HD/github/lang/v
VMODULES: OK, value: /home/mars/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.34.1
Git vroot status: weekly.2024.30-3-g6e8124fd (1 commit(s) behind V master)
.git/config present: true

CC version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
thirdparty/tcc status: thirdparty-linux-amd64 a0799a5b

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@kbkpbot kbkpbot added the Feature Request This issue is made to request a feature. label Jul 23, 2024
@felipensp
Copy link
Member

See vlib/net/conv/conv.v

@kbkpbot
Copy link
Contributor Author

kbkpbot commented Jul 23, 2024

See vlib/net/conv/conv.v

But these functions work depend on machine's endian.
Maybe we should add more functions there?

@JalonSolov
Copy link
Contributor

JalonSolov commented Jul 23, 2024

It could be useful to have more generalized functions. Or one generic. Especially if you want the opposite byte order from what they handle (as you rightly point out, they only work based on the endianness of the current CPU).

Either way, the functions that are already there could work for what you want, if you're using the specific sizes they handle. They only do 16-bit, 32-bit, and 64-bit though... not 128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

No branches or pull requests

3 participants