> For the complete documentation index, see [llms.txt](https://hub.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hub.bsvblockchain.org/higher-learning/bsv-academy/hash-functions/walkthrough-implementation-of-ripemd-160-in-golang/ripemd-160-final-value-construction-and-output.md).

# RIPEMD-160 Final Value Construction and Output

{% embed url="<https://youtu.be/yukEttxD9D0>" %}

## Final Value Construction

The last step in the RIPEMD-160 hash function is to build the final value and print it to standard output in hexadecimal.

In our implementation of RIPEMD-160, we use the function PrintFinalHashValuesInHex to build our output value from our calculated hash values, i.e. final chaining values:

```markup
func PrintFinalHashValuesInHex(hashValues []uint32) string { 

      finalValue := make([]byte, 20) 

      binary.LittleEndian.PutUint32(finalValue[0:], hashValues[0]) 
      binary.LittleEndian.PutUint32(finalValue[4:], hashValues[1]) 
      binary.LittleEndian.PutUint32(finalValue[8:], hashValues[2]) 
      binary.LittleEndian.PutUint32(finalValue[12:], hashValues[3]) 
      binary.LittleEndian.PutUint32(finalValue[16:], hashValues[4])  

      return fmt.Sprintf("%x", finalValue) 
} 
```

We then we return it to our main input/output function and print it to standard output:

```markup
func main() { 
 
      fi, _ := os.Stdin.Stat() 

      if (fi.Mode() & os.ModeCharDevice) == 0 { 
            reader := bufio.NewReader(os.Stdin) 
            input, _ := reader.ReadString('\n') 
            input = strings.TrimSuffix(input, "\n") 
            fmt.Println(GetHash(input)) 
      } else { 
  
            if len(os.Args) > 1 && len(os.Args) < 3 {  

                  fmt.Println(GetHash(os.Args[1])) 
 
            } else { 
                  fmt.Println("Please provide a single input string") 
            } 
      }   

} 
```

And that's how RIPEMD-160 works. And we can verify its correctness by testing it against the test values supplied in Dobbertin et. al.'s paper:

```markup
// Input abc 
// Expected Output: 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc 
  
➜  ripemd160-example git:(main) ./ripemd160-example abc 
8eb208f7e05d987a9b044a8e98c6b087f15a0bfc 
  
// Input: a 1 million times 
// Expected Output: 52783243c1697bdbe16d37f97f68f08325dc1528 
  
➜  ripemd160-example git:(main) printf a%0.s {1..1000000} | ./ripemd160-example 
52783243c1697bdbe16d37f97f68f08325dc1528
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hub.bsvblockchain.org/higher-learning/bsv-academy/hash-functions/walkthrough-implementation-of-ripemd-160-in-golang/ripemd-160-final-value-construction-and-output.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
