How to calculate the CRC32 of 1 by hand? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 254
Joined: 06 Dec 2018, 04:36

How to calculate the CRC32 of 1 by hand?

16 Mar 2019, 15:54

How to calculate the CRC32 of 1 by hand?


100000000000000000000000000000000
100000100110000010001110110110111
----------------------------------------------------
100110000010001110110110111


Why the result is not 0xA505DF1B?
User avatar
jeeswg
Posts: 5933
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to calculate the CRC32 of 1 by hand?

16 Mar 2019, 20:31

There's also this:
CRC-32 hash tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=35671
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
IMEime
Posts: 735
Joined: 20 Sep 2014, 06:15

Re: How to calculate the CRC32 of 1 by hand?

16 Mar 2019, 20:42

Ho.. really good one
-I just SIMPLE Googled, and pick the several ones from the first of the page
afe
Posts: 254
Joined: 06 Dec 2018, 04:36

Re: How to calculate the CRC32 of 1 by hand?

Yesterday, 00:56

jeeswg wrote:
16 Mar 2019, 20:31
There's also this:
CRC-32 hash tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=35671
I have already read this post from you, but I still don't understand why to do this?.
Are you using ISO/IEC/IEEE 802-3 CRC32? Where is the document for ISO/IEC/IEEE 802-3 CRC32?
Last edited by afe on 17 Mar 2019, 06:06, edited 1 time in total.
User avatar
jeeswg
Posts: 5933
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to calculate the CRC32 of 1 by hand?

Yesterday, 05:16

- You can test here:
Online CRC-8 CRC-16 CRC-32 Calculator
https://crccalc.com/
- For the 1-byte ASCII character 1, which is Chr(49) = Chr(0x31), which is the 1-byte hex 0x31 = 0b00110001 you get CRC-32 hash 0x83DCEFB7.
- For the 1-byte hex 0x01 = 0b00000001, you get CRC-32 hash 0xA505DF1B.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
afe
Posts: 254
Joined: 06 Dec 2018, 04:36

Re: How to calculate the CRC32 of 1 by hand?

Yesterday, 06:03

Where does the basis of your algorithm come from?

This is my hand calculation step according to the algorithm of CRC-8/CRC-16.

Input data: 0x1 = 0b00000001

polynomial: 100000100110000010001110110110111


append:

Code: Select all

0000000100000000000000000000000000000000
        --------------------------------
                                     32
XOR:

Code: Select all

0000000100000000000000000000000000000000
       100000100110000010001110110110111
---------------------------------------
       000000100110000010001110110110111  =  0x4C11DB7
The CRC value is 4C11DB7.
Last edited by afe on 17 Mar 2019, 06:34, edited 1 time in total.
User avatar
jeeswg
Posts: 5933
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to calculate the CRC32 of 1 by hand?  Topic is solved

Yesterday, 06:28

Here are some calculations:

Code: Select all

calculate the CRC-32 hash for hex '01':

inputs:
dividend: binary for hex '01': 0b00000001 = 0x01 = 1
polynomial: 0b100000100110000010001110110110111 = 0x104C11DB7

0b00000001 = 0x01
reverse bits in each byte:
0b10000000 = 0x80
append 32 0 bits:
0b1000000000000000000000000000000000000000 = 0x8000000000
XOR the first 4 bytes with 0xFFFFFFFF:
0b0111111111111111111111111111111100000000 = 0x7FFFFFFF00

'CRC division':
0111111111111111111111111111111100000000
 100000100110000010001110110110111 = poly (1)
 ---------------------------------
  111110110011111011100010010010110 = 'bits above poly (1)' ^ poly
  100000100110000010001110110110111 = poly (2)
  ---------------------------------
   111100101011110011011001001000010 = 'bits above poly (2)' ^ poly
   100000100110000010001110110110111 = poly (3)
   ---------------------------------
    111000011011100010101111111101010 = 'bits above poly (3)' ^ poly
    100000100110000010001110110110111 = poly (4)
    ---------------------------------
     110001111011000001000010010111010 = 'bits above poly (4)' ^ poly
     100000100110000010001110110110111 = poly (5)
     ---------------------------------
      100010111010000110011001000011010 = 'bits above poly (5)' ^ poly
      100000100110000010001110110110111 = poly (6)
      ---------------------------------
          100111000001000101111101011010 = 'bits above poly (6)' ^ poly = remainder

remainder: 0b00100111000001000101111101011010 = 0x27045F5A
XOR the remainder with 0xFFFFFFFF:
0b11011000111110111010000010100101 = 0xD8FBA0A5
reverse bits:
0b10100101000001011101111100011011 = 0xA505DF1B

thus the CRC-32 hash for hex '01' is 0xA505DF1B
I cite various sources in my tutorial, however, I did not come across any official sources.

Here is some code to do the calculations by hand:

Code: Select all

q:: ;calculate CRC-32 hashes by hand
vBin := "0111111111111111111111111111111100000000"
vPoly := "100000100110000010001110110110111"
vLenPoly := StrLen(vPoly)
vOutput := ""
Loop
{
	vBin := LTrim(vBin, "0")
	if (StrLen(vBin) < vLenPoly)
		break
	vTemp1 := SubStr(vBin, 1, vLenPoly)
	vTemp2 := SubStr(vBin, vLenPoly+1)
	vTemp1X := JEE_BinXor(vTemp1, vPoly)
	vBin := vTemp1X vTemp2
	vOutput .= vTemp1X " " vTemp2 " " JEE_BinToHex(vTemp1X) "`r`n"
}
vBin := LTrim(vBin, "0")
vOutput .= "`r`n" vBin " " JEE_BinToHex(vBin)
vBin := JEE_BinXor(vBin, "11111111111111111111111111111111") ;0xFFFFFFFF
vOutput .= "`r`n" vBin " " JEE_BinToHex(vBin)
vBin := JEE_StrReverse(vBin)
vOutput .= "`r`n" vBin " " JEE_BinToHex(vBin)
Clipboard := vOutput "`r`n"
MsgBox, % "done"
return

JEE_BinXor(vBin1, vBin2)
{
	local
	vLen := Max(StrLen(vBin1), StrLen(vBin2))
	vBin1 := Format("{:0" vLen "}", vBin1)
	vBin2 := Format("{:0" vLen "}", vBin2)
	vOutput := ""
	Loop, % vLen
		vOutput .= !(SubStr(vBin1, A_Index, 1) = SubStr(vBin2, A_Index, 1))
	;MsgBox, % vBin1 "`r`n" vBin2 "`r`n" vOutput
	return vOutput
}

;JEE_Bin2Hex
JEE_BinToHex(vBin)
{
	local
	vIndex := StrLen(vBin)

	;bin2dec
	vOutput := 0
	Loop, Parse, vBin
	{
		vIndex--
		vOutput += A_LoopField * (2**vIndex)
	}

	;dec2hex
	return Format("{:X}", vOutput)
}

JEE_StrReverse(vText)
{
	local
	vLen := StrLen(vText)
	vOutput := ""
	VarSetCapacity(vOutput, vLen*2)

	Loop, % vLen
		vOutput .= SubStr(vText, vLen-A_Index+1, 1)
		;vOutput .= SubStr(vText, vLen--, 1) ;could use
	return vOutput
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
afe
Posts: 254
Joined: 06 Dec 2018, 04:36

Re: How to calculate the CRC32 of 1 by hand?

Yesterday, 06:41

XOR the first 4 bytes with 0xFFFFFFFF:
Where does this basis come from?

I have read this paper
http://www.ross.net/crc/crcpaper.html
, but until now I can't find the official documentation for CRC-32.
User avatar
jeeswg
Posts: 5933
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to calculate the CRC32 of 1 by hand?

Yesterday, 07:57

These are the best 3 sources I found:

[explains 'CRC division']
crc_v3.txt
http://www.ross.net/crc/download/crc_v3.txt

[calculates the CRC-32 hash for ASCII 'a', i.e. hex '97']
How to calculate CRC32 by hand? – An Integrated World
https://www.anintegratedworld.com/how-to-calculate-crc32-by-hand/

[the procedure neatly summarised]
c - How is a CRC32 checksum calculated? - Stack Overflow
https://stackoverflow.com/a/44805358
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
afe
Posts: 254
Joined: 06 Dec 2018, 04:36

Re: How to calculate the CRC32 of 1 by hand?

Yesterday, 13:46

Thank you very much!

Return to “Ask For Help”

Who is online

Users browsing this forum: alonzam99, Bing [Bot], bojo5150, esp901, Flipeador, Google [Bot], paik1002, teadrinker and 37 guests