# Why does int8 left bitshift become negative on 8th bit?

**URL:** <https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856>\
**Category:** Getting Help\
**Created:** [December 8, 2022, 1:45pm UTC](https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856 "2022-12-08T13:45:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Levy](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/andy_levy/32/12471_2.png) [@Andy\_Levy](https://forum.golangbridge.org/u/Andy_Levy)\
**Post date:** [December 8, 2022, 1:45pm UTC](https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856/1 "2022-12-08T13:45:02Z")

</div>

[https://play.golang.com/p/TyFQoBR9dQr](https://play.golang.com/p/TyFQoBR9dQr)

package main

import (  
“fmt”  
)

func main() {  
var c int8 = 1 // 00000001  
fmt.Println(c \<\< 6) // 01000000 = 64  
fmt.Println(c \<\< 7) // 10000000 = -128 ???  
}

---

<div class="post-metadata">

**Author:** ![Andy\_Levy](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/andy_levy/32/12471_2.png) [@Andy\_Levy](https://forum.golangbridge.org/u/Andy_Levy)\
**Post date:** [December 8, 2022, 1:55pm UTC](https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856/3 "2022-12-08T13:55:08Z")

</div>

Because the int8 is unsigned - so the last bit decides the direction

---

<div class="post-metadata">

**Author:** ![skillian](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/skillian/32/7876_2.png) [@skillian](https://forum.golangbridge.org/u/skillian)\
**Post date:** [December 8, 2022, 2:52pm UTC](https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856/4 "2022-12-08T14:52:03Z")

</div>

It looks like you may have already figured it out, but please see [Two’s complement - Wikipedia](https://en.wikipedia.org/wiki/Two%27s_complement) for more information on what’s happening.

---

<div class="post-metadata">

**Author:** ![sabitk](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/sabitk/32/12444_2.png) [@sabitk](https://forum.golangbridge.org/u/sabitk)\
**Post date:** [December 11, 2022, 3:39pm UTC](https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856/5 "2022-12-11T15:39:09Z")

</div>

if first bit starts with 1 it’s a negative number, otherwise a positive one

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [March 11, 2023, 3:39pm UTC](https://forum.golangbridge.org/t/why-does-int8-left-bitshift-become-negative-on-8th-bit/29856/6 "2023-03-11T15:39:45Z")

</div>

Closed on March 11, 2023, 3:39pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
