• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Binary Numbers: 1-1023

Useful for writing resources like Hamming Code.

Powers of 2:
001, 002, 004, 008, 016, 032, 064, 128, 256, 512
001, 002, 003, 004, 005, 006, 007, 008, 009, 010

Code:
0000000001		1
0000000010		2
0000000011		3
0000000100		4
0000000101		5
0000000110		6
0000000111		7
0000001000		8
0000001001		9
0000001010		10
0000001011		11
0000001100		12
0000001101		13
0000001110		14
0000001111		15
0000010000		16
0000010001		17
0000010010		18
0000010011		19
0000010100		20
0000010101		21
0000010110		22
0000010111		23
0000011000		24
0000011001		25
0000011010		26
0000011011		27
0000011100		28
0000011101		29
0000011110		30
0000011111		31
0000100000		32
0000100001		33
0000100010		34
0000100011		35
0000100100		36
0000100101		37
0000100110		38
0000100111		39
0000101000		40
0000101001		41
0000101010		42
0000101011		43
0000101100		44
0000101101		45
0000101110		46
0000101111		47
0000110000		48
0000110001		49
0000110010		50
0000110011		51
0000110100		52
0000110101		53
0000110110		54
0000110111		55
0000111000		56
0000111001		57
0000111010		58
0000111011		59
0000111100		60
0000111101		61
0000111110		62
0000111111		63
0001000000		64
0001000001		65
0001000010		66
0001000011		67
0001000100		68
0001000101		69
0001000110		70
0001000111		71
0001001000		72
0001001001		73
0001001010		74
0001001011		75
0001001100		76
0001001101		77
0001001110		78
0001001111		79
0001010000		80
0001010001		81
0001010010		82
0001010011		83
0001010100		84
0001010101		85
0001010110		86
0001010111		87
0001011000		88
0001011001		89
0001011010		90
0001011011		91
0001011100		92
0001011101		93
0001011110		94
0001011111		95
0001100000		96
0001100001		97
0001100010		98
0001100011		99
0001100100		100
0001100101		101
0001100110		102
0001100111		103
0001101000		104
0001101001		105
0001101010		106
0001101011		107
0001101100		108
0001101101		109
0001101110		110
0001101111		111
0001110000		112
0001110001		113
0001110010		114
0001110011		115
0001110100		116
0001110101		117
0001110110		118
0001110111		119
0001111000		120
0001111001		121
0001111010		122
0001111011		123
0001111100		124
0001111101		125
0001111110		126
0001111111		127
0010000000		128
0010000001		129
0010000010		130
0010000011		131
0010000100		132
0010000101		133
0010000110		134
0010000111		135
0010001000		136
0010001001		137
0010001010		138
0010001011		139
0010001100		140
0010001101		141
0010001110		142
0010001111		143
0010010000		144
0010010001		145
0010010010		146
0010010011		147
0010010100		148
0010010101		149
0010010110		150
0010010111		151
0010011000		152
0010011001		153
0010011010		154
0010011011		155
0010011100		156
0010011101		157
0010011110		158
0010011111		159
0010100000		160
0010100001		161
0010100010		162
0010100011		163
0010100100		164
0010100101		165
0010100110		166
0010100111		167
0010101000		168
0010101001		169
0010101010		170
0010101011		171
0010101100		172
0010101101		173
0010101110		174
0010101111		175
0010110000		176
0010110001		177
0010110010		178
0010110011		179
0010110100		180
0010110101		181
0010110110		182
0010110111		183
0010111000		184
0010111001		185
0010111010		186
0010111011		187
0010111100		188
0010111101		189
0010111110		190
0010111111		191
0011000000		192
0011000001		193
0011000010		194
0011000011		195
0011000100		196
0011000101		197
0011000110		198
0011000111		199
0011001000		200
0011001001		201
0011001010		202
0011001011		203
0011001100		204
0011001101		205
0011001110		206
0011001111		207
0011010000		208
0011010001		209
0011010010		210
0011010011		211
0011010100		212
0011010101		213
0011010110		214
0011010111		215
0011011000		216
0011011001		217
0011011010		218
0011011011		219
0011011100		220
0011011101		221
0011011110		222
0011011111		223
0011100000		224
0011100001		225
0011100010		226
0011100011		227
0011100100		228
0011100101		229
0011100110		230
0011100111		231
0011101000		232
0011101001		233
0011101010		234
0011101011		235
0011101100		236
0011101101		237
0011101110		238
0011101111		239
0011110000		240
0011110001		241
0011110010		242
0011110011		243
0011110100		244
0011110101		245
0011110110		246
0011110111		247
0011111000		248
0011111001		249
0011111010		250
0011111011		251
0011111100		252
0011111101		253
0011111110		254
0011111111		255
0100000000		256
0100000001		257
0100000010		258
0100000011		259
0100000100		260
0100000101		261
0100000110		262
0100000111		263
0100001000		264
0100001001		265
0100001010		266
0100001011		267
0100001100		268
0100001101		269
0100001110		270
0100001111		271
0100010000		272
0100010001		273
0100010010		274
0100010011		275
0100010100		276
0100010101		277
0100010110		278
0100010111		279
0100011000		280
0100011001		281
0100011010		282
0100011011		283
0100011100		284
0100011101		285
0100011110		286
0100011111		287
0100100000		288
0100100001		289
0100100010		290
0100100011		291
0100100100		292
0100100101		293
0100100110		294
0100100111		295
0100101000		296
0100101001		297
0100101010		298
0100101011		299
0100101100		300
0100101101		301
0100101110		302
0100101111		303
0100110000		304
0100110001		305
0100110010		306
0100110011		307
0100110100		308
0100110101		309
0100110110		310
0100110111		311
0100111000		312
0100111001		313
0100111010		314
0100111011		315
0100111100		316
0100111101		317
0100111110		318
0100111111		319
0101000000		320
0101000001		321
0101000010		322
0101000011		323
0101000100		324
0101000101		325
0101000110		326
0101000111		327
0101001000		328
0101001001		329
0101001010		330
0101001011		331
0101001100		332
0101001101		333
0101001110		334
0101001111		335
0101010000		336
0101010001		337
0101010010		338
0101010011		339
0101010100		340
0101010101		341
0101010110		342
0101010111		343
0101011000		344
0101011001		345
0101011010		346
0101011011		347
0101011100		348
0101011101		349
0101011110		350
0101011111		351
0101100000		352
0101100001		353
0101100010		354
0101100011		355
0101100100		356
0101100101		357
0101100110		358
0101100111		359
0101101000		360
0101101001		361
0101101010		362
0101101011		363
0101101100		364
0101101101		365
0101101110		366
0101101111		367
0101110000		368
0101110001		369
0101110010		370
0101110011		371
0101110100		372
0101110101		373
0101110110		374
0101110111		375
0101111000		376
0101111001		377
0101111010		378
0101111011		379
0101111100		380
0101111101		381
0101111110		382
0101111111		383
0110000000		384
0110000001		385
0110000010		386
0110000011		387
0110000100		388
0110000101		389
0110000110		390
0110000111		391
0110001000		392
0110001001		393
0110001010		394
0110001011		395
0110001100		396
0110001101		397
0110001110		398
0110001111		399
0110010000		400
0110010001		401
0110010010		402
0110010011		403
0110010100		404
0110010101		405
0110010110		406
0110010111		407
0110011000		408
0110011001		409
0110011010		410
0110011011		411
0110011100		412
0110011101		413
0110011110		414
0110011111		415
0110100000		416
0110100001		417
0110100010		418
0110100011		419
0110100100		420
0110100101		421
0110100110		422
0110100111		423
0110101000		424
0110101001		425
0110101010		426
0100101011		427
0110101100		428
0110101101		429
0110101110		430
0110101111		431
0110110000		432
0110110001		433
0110110010		434
0110110011		435
0110110100		436
0110110101		437
0110110110		438
0110110111		439
0110111000		440
0110111001		441
0110111010		442
0110111011		443
0110111100		444
0110111101		445
0110111110		446
0110111111		447
0111000000		448
0111000001		449
0111000010		450
0111000011		451
0111000100		452
0111000101		453
0111000110		454
0111000111		455
0111001000		456
0111001001		457
0111001010		458
0111001011		459
0111001100		460
0111001101		461
0111001110		462
0111001111		463
0111010000		464
0111010001		465
0111010010		466
0111010011		467
0111010100		468
0111010101		469
0111010110		470
0111010111		471
0111011000		472
0111011001		473
0111011010		474
0111011011		475
0111011100		476
0111011101		477
0111011110		478
0111011111		479
0111100000		480
0111100001		481
0111100010		482
0111100011		483
0111100100		484
0111100101		485
0111100110		486
0111100111		487
0111101000		488
0111101001		489
0111101010		490
0111101011		491
0111101100		492
0111101101		493
0111101110		494
0111101111		495
0111110000		496
0111110001		497
0111110010		498
0111110011		499
0111110100		500
0111110101		501
0111110110		502
0111110111		503
0111111000		504
0111111001		505
0111111010		506
0111111011		507
0111111100		508
0111111101		509
0111111110		510
0111111111		511
1000000000		512
1000000001		513
1000000010		514
1000000011		515
1000000100		516
1000000101		517
1000000110		518
1000000111		519
1000001000		520
1000001001		521
1000001010		522
1000001011		523
1000001100		524
1000001101		525
1000001110		526
1000001111		527
1000010000		528
1000010001		529
1000010010		530
1000010011		531
1000010100		532
1000010101		533
1000010110		534
1000010111		535
1000011000		536
1000011001		537
1000011010		538
1000011011		539
1000011100		540
1000011101		541
1000011110		542
1000011111		543
1000100000		544
1000100001		545
1000100010		546
1000100011		547
1000100100		548
1000100101		549
1000100110		550
1000100111		551
1000101000		552
1000101001		553
1000101010		554
1000101011		555
1000101100		556
1000101101		557
1000101110		558
1000101111		559
1000110000		560
1000110001		561
1000110010		562
1000110011		563
1000110100		564
1000110101		565
1000110110		566
1000110111		567
1000111000		568
1000111001		569
1000111010		570
1000111011		571
1000111100		572
1000111101		573
1000111110		574
1000111111		575
1001000000		576
1001000001		577
1001000010		578
1001000011		579
1001000100		580
1001000101		581
1001000110		582
1001000111		583
1001001000		584
1001001001		585
1001001010		586
1001001011		587
1001001100		588
1001001101		589
1001001110		590
1001001111		591
1001010000		592
1001010001		593
1001010010		594
1001010011		595
1001010100		596
1001010101		597
1001010110		598
1001010111		599
1001011000		600
1001011001		601
1001011010		602
1001011011		603
1001011100		604
1001011101		605
1001011110		606
1001011111		607
1001100000		608
1001100001		609
1001100010		610
1001100011		611
1001100100		612
1001100101		613
1001100110		614
1001100111		615
1001101000		616
1001101001		617
1001101010		618
1001101011		619
1001101100		620
1001101101		621
1001101110		622
1001101111		623
1001110000		624
1001110001		625
1001110010		626
1001110011		627
1001110100		628
1001110101		629
1001110110		630
1001110111		631
1001111000		632
1001111001		633
1001111010		634
1001111011		635
1001111100		636
1001111101		637
1001111110		638
1001111111		639
1010000000		640
1010000001		641
1010000010		642
1010000011		643
1010000100		644
1010000101		645
1010000110		646
1010000111		647
1010001000		648
1010001001		649
1010001010		650
1010001011		651
1010001100		652
1010001101		653
1010001110		654
1010001111		655
1010010000		656
1010010001		657
1010010010		658
1010010011		659
1010010100		660
1010010101		661
1010010110		662
1010010111		663
1010011000		664
1010011001		665
1010011010		666
1010011011		667
1010011100		668
1010011101		669
1010011110		670
1010011111		671
1010100000		672
1010100001		673
1010100010		674
1010100011		675
1010100100		676
1010100101		677
1010100110		678
1010100111		679
1010101000		680
1010101001		681
1010101010		682
1010101011		683
1010101100		684
1010101101		685
1010101110		686
1010101111		687
1010110000		688
1010110001		689
1010110010		690
1010110011		691
1010110100		692
1010110101		693
1010110110		694
1010110111		695
1010111000		696
1010111001		697
1010111010		698
1010111011		699
1010111100		700
1010111101		701
1010111110		702
1010111111		703
1011000000		704
1011000001		705
1011000010		706
1011000011		707
1011000100		708
1011000101		709
1011000110		710
1011000111		711
1011001000		712
1011001001		713
1011001010		714
1011001011		715
1011001100		716
1011001101		717
1011001110		718
1011001111		719
1011010000		720
1011010001		721
1011010010		722
1011010011		723
1011010100		724
1011010101		725
1011010110		726
1011010111		727
1011011000		728
1011011001		729
1011011010		730
1011011011		731
1011011100		732
1011011101		733
1011011110		734
1011011111		735
1011100000		736
1011100001		737
1011100010		738
1011100011		739
1011100100		740
1011100101		741
1011100110		742
1011100111		743
1011101000		744
1011101001		745
1011101010		746
1011101011		747
1011101100		748
1011101101		749
1011101110		750
1011101111		751
1011110000		752
1011110001		753
1011110010		754
1011110011		755
1011110100		756
1011110101		757
1011110110		758
1011110111		759
1011111000		760
1011111001		761
1011111010		762
1011111011		763
1011111100		764
1011111101		765
1011111110		766
1011111111		767
1100000000		768
1100000001		769
1100000010		770
1100000011		771
1100000100		772
1100000101		773
1100000110		774
1100000111		775
1100001000		776
1100001001		777
1100001010		778
1100001011		779
1100001100		780
1100001101		781
1100001110		782
1100001111		783
1100010000		784
1100010001		785
1100010010		786
1100010011		787
1100010100		788
1100010101		789
1100010110		790
1100010111		791
1100011000		792
1100011001		793
1100011010		794
1100011011		795
1100011100		796
1100011101		797
1100011110		798
1100011111		799
1100100000		800
1100100001		801
1100100010		802
1100100011		803
1100100100		804
1100100101		805
1100100110		806
1100100111		807
1100101000		808
1100101001		809
1100101010		810
1100101011		811
1100101100		812
1100101101		813
1100101110		814
1100101111		815
1100110000		816
1100110001		817
1100110010		818
1100110011		819
1100110100		820
1100110101		821
1100110110		822
1100110111		823
1100111000		824
1100111001		825
1100111010		826
1100111011		827
1100111100		828
1100111101		829
1100111110		830
1100111111		831
1101000000		832
1101000001		833
1101000010		834
1101000011		835
1101000100		836
1101000101		837
1101000110		838
1101000111		839
1101001000		840
1101001001		841
1101001010		842
1101001011		843
1101001100		844
1101001101		845
1101001110		846
1101001111		847
1101010000		848
1101010001		849
1101010010		850
1101010011		851
1101010100		852
1101010101		853
1101010110		854
1101010111		855
1101011000		856
1101011001		857
1101011010		858
1101011011		859
1101011100		860
1101011101		861
1101011110		862
1101011111		863
1101100000		864
1101100001		865
1101100010		866
1101100011		867
1101100100		868
1101100101		869
1101100110		870
1101100111		871
1101101000		872
1101101001		873
1101101010		874
1101101011		875
1101101100		876
1101101101		877
1101101110		878
1101101111		879
1101110000		880
1101110001		881
1101110010		882
1101110011		883
1101110100		884
1101110101		885
1101110110		886
1101110111		887
1101111000		888
1101111001		889
1101111010		890
1101111011		891
1101111100		892
1101111101		893
1101111110		894
1101111111		895
1110000000		896
1110000001		897
1110000010		898
1110000011		899
1110000100		900
1110000101		901
1110000110		902
1110000111		903
1110001000		904
1110001001		905
1110001010		906
1110001011		907
1110001100		908
1110001101		909
1110001110		910
1110001111		911
1110010000		912
1110010001		913
1110010010		914
1110010011		915
1110010100		916
1110010101		917
1110010110		918
1110010111		919
1110011000		920
1110011001		921
1110011010		922
1110011011		923
1110011100		924
1110011101		925
1110011110		926
1110011111		927
1110100000		928
1110100001		929
1110100010		930
1110100011		931
1110100100		932
1110100101		933
1110100110		934
1110100111		935
1110101000		936
1110101001		937
1110101010		938
1110101011		939
1110101100		940
1110101101		941
1110101110		942
1110101111		943
1110110000		944
1110110001		945
1110110010		946
1110110011		947
1110110100		948
1110110101		949
1110110110		950
1110110111		951
1110111000		952
1110111001		953
1110111010		954
1110111011		955
1110111100		956
1110111101		957
1110111110		958
1110111111		959
1111000000		960
1111000001		961
1111000010		962
1111000011		963
1111000100		964
1111000101		965
1111000110		966
1111000111		967
1111001000		968
1111001001		969
1111001010		970
1111001011		971
1111001100		972
1111001101		973
1111001110		974
1111001111		975
1111010000		976
1111010001		977
1111010010		978
1111010011		979
1111010100		980
1111010101		981
1111010110		982
1111010111		983
1111011000		984
1111011001		985
1111011010		986
1111011011		987
1111011100		988
1111011101		989
1111011110		990
1111011111		991
1111100000		992
1111100001		993
1111100010		994
1111100011		995
1111100100		996
1111100101		997
1111100110		998
1111100111		999
1111101000		1000
1111101001		1001
1111101010		1002
1111101011		1003
1111101100		1004
1111101101		1005
1111101110		1006
1111101111		1007
1111110000		1008
1111110001		1009
1111110010		1010
1111110011		1011
1111110100		1012
1111110101		1013
1111110110		1014
1111110111		1015
1111111000		1016
1111111001		1017
1111111010		1018
1111111011		1019
1111111100		1020
1111111101		1021
1111111110		1022
1111111111		1023
 
Just wrote this:

JASS:
library Binary

    globals
        private integer array pow2
    endglobals
    
    function Int2Binary takes integer int returns string
        local integer i = 30
        local string result = ""
        local boolean started = false
        
        if int >= 0 then
            loop
                if int >= pow2[i] then
                    set result = result + "1"
                    set int = int - pow2[i]
                    set started = true
                else
                    if started then
                        set result = result + "0"
                    endif
                endif
                exitwhen i == 0
                set i = i - 1
            endloop
        else
            return "0"
        endif
        
        return result
    endfunction
    
    function Binary2Int takes string s returns integer
        local integer length = StringLength(s)
        local integer i = 0
        local integer result = 0
        
        loop
            if SubString(s, i, i + 1) == "1" then
                set result = result + pow2[length - i - 1]
            endif
            set i = i + 1
            exitwhen i == 31
        endloop
        
        return result
    endfunction
    
    private module Init
        private static method onInit takes nothing returns nothing
            local integer i = 0
            local integer p = 1
            
            loop
                set pow2[i] = p
                set p = p * 2
                set i = i + 1
                exitwhen i == 31
            endloop
            
        endmethod
    endmodule
    
    private struct Inits extends array
        implement Init
    endstruct

endlibrary

Happy? :>
 
Top