0
\$\begingroup\$

Intro:

This is a twist on a previous question of mine: Counting from 1 to an Integer... in Binary.

Many of this question's rules and that question's rules are the same. Here is the intro from that question:

I remember, when I was a kid, I would get a calculator and keep on pressing the + button, and see how high I could count. Now, I like to program, and I'm developing for iOS.

Counting is a fundamental skill for both humans and computers alike to do. Without it, the rest of math can't be done. It's done simply by starting at 1 and repetitively adding 1 to it.

Yes, computers use binary. That's why hexadecimal was created. It's easier to use hexadecimal for bitwise calculations than it is to use decimal numbers. Here's an illustration:

Decimal .... Hex ... Bitwise
0 .......... 000 ... 0000000
1 .......... 001 ... 0000001
2 .......... 002 ... 0000010
3 .......... 003 ... 0000011
4 .......... 004 ... 0000100
5 .......... 005 ... 0000101
6 .......... 006 ... 0000110
7 .......... 007 ... 0000111
8 .......... 008 ... 0001000
9 .......... 009 ... 0001001
10.......... 00A ... 0001010
11.......... 00B ... 0001011
12.......... 00C ... 0001100
13.......... 00D ... 0001101
14.......... 00E ... 0001110
15.......... 00F ... 0001111

Note how, when the number is 15dec, the hexadecimal number is Fhex. In Binary, that's the maximum number for a 4-bit processor, as it evaluates to 1111binary.

Hexadecimal actually makes it easy to get max numbers for different bit processors. Another illustration:

Processor type ......  Hex value .....                              Binary ... Decimal
4-bit ...............          F .....                                 1111 ... 15
8-bit ...............         FF .....                             11111111 ... 255
16-bit...............       FFFF .....                     1111111111111111 ... 65535
32-bit...............   FFFFFFFF .....     11111111111111111111111111111111 ... 2147483647

And then 64-bit is FFFFFFFFFFFFFFFF, 128-bit is FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, 256-bit is FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, and 512-bit is FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.

Add 1 to any of those numbers and you get either an error or glitchy behavior, known as Integer Overflow. Examples of this in the real world include Pac-Man's Level 256 Kill Screen.


The challenge:

This is but a simple challenge. What I would like your program to do is print from 1 to whatever Integer it takes in. However, I'll throw a twist in it, since decimal counting is kinda boring:

The counting cannot be in base 10, it has to show itself counting in binary.

So, to count to 5, using 32-bit integers, it would look like this:

0000 0000 0000 0000 0000 0000 0000 0001 ..... 1
0000 0000 0000 0000 0000 0000 0000 0010 ..... 2
0000 0000 0000 0000 0000 0000 0000 0011 ..... 3
0000 0000 0000 0000 0000 0000 0000 0100 ..... 4
0000 0000 0000 0000 0000 0000 0000 0101 ..... 5

It's a computer. They know binary best. Your input can be either a 32-bit or 64-bit integer. It is truly up to you. However, if you use 32-bit integers, your output must be 32-bit integers in binary, and if you use 64-bit integers, your output must be 64-bit integers in binary.

-"Counting from 1 to an Integer... In Binary"

This twist involves counting in hexadecimal instead of binary. The bit rule is still the same; if your program runs in 32-bit, it must output in 32-bit.


Sample Input

Any integer number, e.g., 20


Sample Output

Counting to the integer number. In this case, it would return:

00
01
02
03
04
05
06
07
08
09
0A
0B
0C
0D
0E
0F
10
11
12
13
14

Scoring

This is Code Golf. Lowest character count wins. There was some debate about that last time.


Making bit ambiguity unambiguous

I understand some languages have floating bit precision or arbitrary precision. To make this less confusing, I'm making standard bit counts a bonus, and 64 bits will be a second bonus. Standard counts are optional, but probably easier to program in some languages.


Bonuses

Score is a floating point value. This question retains a slightly modified version of one of the bonuses from the previous question:

If you show, in the output, the number it's at as a base 10 number (for example, 0000 0000 0000 0000 0000 0000 0000 0001 in binary is equal to the base 10 1), multiply your score by 0.8.

The modification is, you're going from hexadecimal to decimal, not binary to decimal.

Now, for other bonuses:

  • Multiply by 0.95 if your bit precision is a power of 2.
  • Multiply by 0.95 again if you are using 64-bit precision or higher (still being standard bit precision).

Good luck!

\$\endgroup\$
4
  • \$\begingroup\$ Does case matter? \$\endgroup\$ – Downgoat Aug 17 '15 at 4:03
  • \$\begingroup\$ @vihan no. Case doesn't matter. F can be F or f. \$\endgroup\$ – DDPWNAGE Aug 17 '15 at 4:03
  • \$\begingroup\$ @DDPWNAGE What about the 0's at the beginning, any rules on those? If it needs to be fixed? Can the output be an array, a space separated string? Is a trailing newline allowed? \$\endgroup\$ – Downgoat Aug 17 '15 at 4:07
  • \$\begingroup\$ @vihan Trailing zeroes are allowed, and the output should probably be a space separated string. \$\endgroup\$ – DDPWNAGE Aug 17 '15 at 4:09

Browse other questions tagged or ask your own question.