Reg 0 slicing in int64

Hi Team,

I am trying to print 02 as below code.

n:= int64(02)
fmt.Println(n)

But i am getting 2 only.It always slice 0.How to print 02 instead of 2?

Which base 10 integer is 02 supposed to be? 2?

I am working on getting Video headers.I am getting below output in wireshark 71,02,25,22

But go Program i am getting below output while iterating packet details

71,2,25,22

Due to this binary value are changing.

Thanks,
Raja

So you are getting textual output that you want to parse? Is 02 text output from wireshark?

yes

Then please show us your Go code that converts the text output

71,02,25,22

to four integers.

         data = hexvalue
	for i = 0; i < 4; i++ {

		n = int64(pkt[i])
		fmt.Println(n)
		hexvalue = strconv.FormatInt(n, 16)
		data += hexvalue

	}

	fmt.Println("HexValue-", data)"

Here n returns 71,2,25,22 but i want 71,02,25,22

What is pkt?

Please, don’t let’s do it like this. Ask a question that can be answered. Provide all information necessary to understand your problem and your attempt solution. Take a look at:

2 Likes

pkt[i] contains header values.I need first 4 packet values hence i have iterated first four packet value and which will return below output
71
2
25
22

Thanks,
Raja

No. Please go and read about how a good question is asked. Then work on your question. Ask yourself: Would you understand it if you knew nothing but the information included in it? If not, rework your question. Only after you can answer yes, come here, post your question. And please take a look at the tools provided here to post code in a readable way.

ok Sure.Thanks

Well, taking a look at your other questions that we tried to answer during the last days, I am not so sure. We are all here to help but you must help us being able to help you.

If you want to print an integer with leading zeros you can use something like the fmt package to do so - https://play.golang.org/p/GwjGeT9g9GT

If you want your code to differentiate between when it parsed 02 and when it parsed 2 that is a very different problem and it depends on your code a little more.

Use Sprintf like this
var str = fmt.Sprintf("%02d", 2)

1 Like

Yes I tried already this and it was working.Thanks

Well, when I see this, I do not think that the proposed fmt.Sprintf is the thin you really want… What do you want to see when n is decimal 10? Do you want to see hex 0a or Dec 10?

1 Like

Help Vampire: http://www.skidmore.edu/~pdwyer/e/eoc/help_vampire.htm

2 Likes

I’m aware of how old and irritating it can get sometimes, I’ve suffered it myself, but the reference just seems a bit harsh. Yeah, @lutzhorn, @NobbZ, @calmh, you, and others that frequently respond to topics probably have better things to do over guessing what the poster is asking when the question isn’t clear or well explained, or worse, seems a demand that someone else solves their issues, tasks, doubts, etc. I get it, I really do. But sometimes we should consider other factors too: maybe someone is trying to get something working in an environment that he is new to and has no clue of what is relevant about it (and, thus, doesn’t know what should be included when asking about it); sometimes people don’t know how to express their needs or doubts because english isn’t their first language and can’t find the words to make the question clear (heck, I’m not a native english speaker*, which is probably hinted by the frequent use of commas, really long sentences and somewhat repeating vocabulary); sometimes people are new to a community and aren’t aware of their idiosyncrasy and common rules; or simply sometimes people are new to the whole programming “thing” and are just looking for a helping hand.

Again, yes, I’ve been frustrated after getting 20 or more questions from a same person in gitter (not even about my project, just trying to help), answering them the best as I could and having the 21rst one being in chinese and being asked to “google translate it and please respond as soon as possible” (again, I’m not even a native english speaker, nevermind chinese, I speak spanish!*).

But even then, I tend to remember 2 particular things. The first is that I was once a newebie too. I remember being in my first week of “Introduction to programming” (¿programming 101?), all excited and whatnot about computers, and having my first external CD/DVD burner delivered, opening my computer case and wondering how the hell was I supposed to connect it if the IDE “wires” were already taken (didn’t know squat about master and slave, buses, motherboards, etc.), and I was afraid to ask about it for two reasons: I didn’t want to look stupid or ignorant, and I didn’t know how to ask the right questions because I lacked the necessary technical terms. Though now I have a pretty good picture, I still don’t know a lot about computers and their hardware internals, which is still scary as I work with electrical and electronics engineers on my team.

The second one I think is the real reason why I’m posting this: I can’t recall how many times it’s been, but it must have been hundreds of times I’ve spent time telling others and going on over how I really like the computer’s science, programming, hacking, etc. community in general, where people will go off their way to create and code things for other to use, test new software to give feedback, answer questions in forums and commonly just help each other. People in tech just seem to be that nice and, in this world, it’s a really refreshing thing to encounter. I may be wrong, but it’s something I haven’t seen in many other fields.

To wrap it up, nowadays I have 6 years of computer science / engineering university education (it iwas 2 years of common engineering and 4 of computer science in my country to get a degree), another 6 years of professional experience and almost a year of Go experience (still very much to learn), and I really enjoy giving something back, being it building an open source project, contributing to someone else’s or helping a bit by answering questions in forums or other communities. And I also enjoy very much reading about issues I know nothing about and learning from others that do. So yes, we all get annoyed sometimes, I’ve gotten tired after answering 40 times how to configure a postgres instance for something that is documented, but please let’s keep maintaining and building a great community of gophers, coders, computer scientists, etc.

Please don’t take this as anything against your or other’s posts, but as an encouragement to keep with your great contributions.

Sorry for the long post. :sweat_smile:

(* Just clearing out that english seems to be the lingua franca of the programming).

1 Like

Good post and no offence taken.

When I started programming back in the 90ties, there was no community, at least nothing that is meant by this word today. There where was no Google, no Stack Overflow, not instant gratification. There was Usenet and there were mailinglists. And of course there were flamewars going on forever. But there also were killfiles.

Those of us that can remember these old days may have mixed feelings. Some things were great, some were ugly. But we dealt with it. We kept going on, maybe because were working hard, maybe because we were talented, maybe just because we were fascinated. But we did not keep going on because we got a warm fuzzy feeling from being part of a global community.

Todays emphasis of most large players in the programming field and the attached communities on diversity, inclusion, being nice, creating safe spaces is irritating. We all know that Google is not building a community because they are Good People™. Google and all the other big players want to make money. Emphasizing the community, mixing it with a very US centric POV on how people must interact in social life while we all know that they would drop all of this in an instant if there were other ways to make money is hypocritical.

1 Like