go版本的supervisord
go和python解码msgpack不一致

golang位移操作的一个小坑

妙音 posted @ 2021年11月25日 16:08 in golang , 810 阅读

问题描述

 
    现有int16类型的整数,将它转为两个字节存放。在还原时,一不小心会就被坑了。
 
 

错误用法

 
length := int(keyBytes[cursor] + keyBytes[cursor+1] <<8)
 

正确用法

 
keyBytes := []byte{ 16, 1}
length := int(uint16(keyBytes[cursor]) + uint16(keyBytes[cursor+1]) <<8)
 

错误原因

 
字节byte位移时类型不会自动变化, 先要转换类型再位移。
 
 
Avatar_small
sophia 说:
2023年6月21日 12:02

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks... 평택출장마사지

Avatar_small
SEO 说:
2023年7月12日 19:30

This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I'm sure that you will be making a really useful place. I has been additionally pleased. Good perform! 천안출장 마사지

Avatar_small
sophia 说:
2023年7月15日 21:34

hello!! Very interesting discussion glad that I came across such informative post. Keep up the good work friend. Glad to be part of your net community. Clicksud

Avatar_small
six components of he 说:
2023年8月09日 16:38

I'm in awe of the quality of content you consistently deliver. This article is top-notch.

Avatar_small
Imamia Quran Academy 说:
2023年8月12日 06:43

Thanks for a very interesting blog. Your blog provided us with valuable information to work with. I am from Imamia Quran Academy. Shia Academy is using this radical idea of taking online classes so that any environmental factor could not disrupt the learning process. Join our Online Shia Quran Academy now, and Start your free 3 days Trial.

Avatar_small
sophia 说:
2023年8月30日 12:20

You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!. เว็บแทงบอลดีที่สุดUFABET

Avatar_small
Johny 说:
2023年8月31日 19:44

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. last minute naar bad waltersdorf


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter