Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:03:28+00:00 2026-05-27T11:03:28+00:00

I recently tried appending two byte array slices in Go and came across some

  • 0

I recently tried appending two byte array slices in Go and came across some odd errors. My code is:

one:=make([]byte, 2)
two:=make([]byte, 2)
one[0]=0x00
one[1]=0x01
two[0]=0x02
two[1]=0x03

log.Printf("%X", append(one[:], two[:]))

three:=[]byte{0, 1}
four:=[]byte{2, 3}

five:=append(three, four)

And the errors are:

cannot use four (type []uint8) as type uint8 in append
cannot use two[:] (type []uint8) as type uint8 in append

Which taken into consideration the alleged robustness of Go’s slices shouldn’t be a problem:

http://code.google.com/p/go-wiki/wiki/SliceTricks

What am I doing wrong, and how should I go about appending two byte arrays?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:03:29+00:00Added an answer on May 27, 2026 at 11:03 am

    The Go Programming Language Specification

    Appending to and copying slices

    The variadic function append appends zero or more values x to s of
    type S, which must be a slice type, and returns the resulting slice,
    also of type S. The values x are passed to a parameter of type ...T
    where T is the element type of S and the respective parameter passing
    rules apply.

    append(s S, x ...T) S // T is the element type of S

    Passing arguments to ... parameters

    If the final argument is assignable to a slice type []T, it may be
    passed unchanged as the value for a ...T parameter if the argument is
    followed by ....


    You need to use []T... for the final argument.

    For your example, with the final argument slice type []byte, the argument is followed by ...,

    package main
    
    import "fmt"
    
    func main() {
        one := make([]byte, 2)
        two := make([]byte, 2)
        one[0] = 0x00
        one[1] = 0x01
        two[0] = 0x02
        two[1] = 0x03
        fmt.Println(append(one[:], two[:]...))
    
        three := []byte{0, 1}
        four := []byte{2, 3}
        five := append(three, four...)
        fmt.Println(five)
    }
    

    Playground: https://play.golang.org/p/2jjXDc8_SWT

    Output:

    [0 1 2 3]
    [0 1 2 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I tried to explain some poorly designed code to my project manager. All
I've recently tried to simplify some of my code by using generics where possible.
I tried recently to use NAnt (beta 0.86.2962.0) to run some unit tests compiled
I recently tried to mirror some input within input(text) fields. Using String.fromCharCode(event.which) for instance,
I recently tried building my own shared and weak pointers. Code that compiles using
I am new to mysql but have recently tried doing some tutorials to advance
I recently tried to install monit on Ubuntu Natty from source. Here's my code:
I recently tried to do something akin to this: a = some string b
I recently tried to make a game server controller in Perl, I would like
I recently tried to combine SEAM and GWT in a project - but failed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.