base 16 notes

This commit is contained in:
Malin Freeborn 2025-03-18 18:11:57 +01:00
parent a72e2b117d
commit 741e988536
Signed by: andonome
GPG Key ID: 52295D2377F4D70F

View File

@ -3,6 +3,24 @@ title: "Base 16"
tags: [ "data" ]
---
```bash
Base 16 numbers often use `0x` at the start, so '10' just means '10', but `0x10` means '10 in base 16' which means '16'.
For small numbers, use `printf`.
```sh
printf "%x" $NUMBER
```
For any number, use `bc`.
```sh
fortune | md5sum | cut -d' ' -f1 | tr [:lower:] [:upper:] | bc
```
- Inputting base 16 uses `ibase=16`.
- Outputting base 10 uses `ibase=10`
```sh
echo 'ibase=16;' $(echo cbb478ac825f0dce7671254be035d0bc | tr [:lower:] [:upper:]) | bc
```