Author Topic: Data Values  (Read 1263 times)

C0deH4cker

  • Hero Member
  • *****
  • Posts: 2849
  • Reputation: 129
  • I am leaving iNinjas. Contact me via email.
  • Badges:
  • iDevices: iPhone 4S 16gb Black (5.1.1), iPad 2 32gb White (5.0.1), iPod Touch 2G 8gb (4.2.1)
Data Values
« on: May 24, 2012, 05:14:35 pm »
In computer science, all types of data read by a computer are simply numbers. For example, even this text that I am currently typing is nothing more than numbers. Each character is exactly one byte in length (Unless special characters are used, such as é or ü). This is known as ASCII encoding.

Let's look at the simplest data storage unit: a bit. A bit is simply a 1 or a 0. This can be represented as true or false, yes or no, on or off, enabled or disabled, etc.

The next step up from a bit is a nibble. A nibble is 4 bits, or half of a byte. Since it has 4 bits (which have 2 possible values), there are 2^4 possible nibbles, or 16 (0-15). A nibble is generally represented as a single hexadecimal digit. Hexadecimal (aka hex) is just a simple way to display base-16 data in a readable and editable format. Counting from 0 to 15 in hexadecimal goes like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. In hex, the number 16 is represented as '0x10'.

Further up is a more familiar value size, a byte. A byte is comprised of 8 bits, or 2 nibbles. This byte can hold up to 2^8 possible values (0-255). Bytes are generally displayed as two "hexits", or hex digits. For example, the byte '3E' corresponds to the decimal number 62. This can be determined by hand. First, look at the leftmost nibble, '3'. Since this is in the second place from the right, you multiply this value by 16 to get 48. Then, you simply add 'E', or 14, to the 48 to get 62. If this byte were to be expressed in "binary," or 1s and 0s, it would be 00111110. Here's a way to easily convert between decimal and binary:

128  64  32  16   8   4   2   1
   *     *    *     *     *   *    *    *
   0    0   1     1    1   1   1   0
  =     =   =    =    =    =  =    =
0 + 0 + 32 + 16 + 8 + 4 + 2 + 0 = 62

To convert hex to binary, just do this (easier):

3         E                Separate out the nibbles
0011   1110          Write each's corresponding value in binary, knowing that the values for each position go like this:  8 4 2 1
00111110             Concatenate all of the binary values. This is your resulting binary representation of the number.


A more complicated example:

Given a hex value, '8B25C601':

8        B        2        5        C       6        0        1
1000  1100  0010  0101  1101  0110  0000  0001
10001100001001011101011000000001



In C, the smallest data type is a 'char', which is simply a byte. For example:

char myByte = 0x3E;

In most programming languages, hex values are prefixed with '0x'. Some older assembly languages (such as 8080) use a '$' prefix, or a 'h' suffix. For this tutorial, however, I will stick with '0x', as this is the most common nowadays.

A 'char' is a character, encoded with ASCII. In ASCII, the character with the value 0x3E is '>'. 'A' is 0x41, while 'a' is 0x61. The rest of the alphabet follows these values. '0' is at 0x30, with '1' at 0x31, and so on. The complete ASCII chart is located here.

Beyond a 'char' is a 'short int', which has a length of 2 bytes, and therefore can have 65536 different values (2^16). Beyond this is an 'int', which is 4 bytes. ints can have 4294967296 possible values (that is 2^32).

After this are longs, long longs, and other data types. These longs and long longs have no specific size and can be platform dependent.

Beyond this, the next most common data types are floats and doubles. These are complicated, and they are beyond the scope of this tutorial, but for now you can simply think of these as numbers that can have decimal points in them. Example (C): float money = 24.99; double angle = 3.14 / 2;
If you are interested in how floats and doubles are stored in memory, then you will find this wikipedia article interesting.



Thanks for reading! This is all for now. If there is anything that you do not understand or you would like for me to add, then just post a comment that says so :).
« Last Edit: May 25, 2012, 10:20:09 pm by C0deH4cker »

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2913
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Data Values
« Reply #1 on: May 24, 2012, 09:08:28 pm »
Very nice. Going to re read tomorrow. Good way to start off this board

LankAsif

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2406
  • Reputation: 90
  • Forum pride 8)
  • Badges:
  • Computers: i7 with bits and pieces
  • iDevices: iPod Touch 1G (Basically storage for iNinja tools), iPhone 5
Re: Data Values
« Reply #2 on: May 25, 2012, 08:15:01 pm »
THANK YOU so much for explaining this C0deH4cker. So happy to read this (I swear).
I think I am a bit slow and got lost at the hex/binary conversions, but love the general tut.
Are "hexits" always double figures?
Thanks again man. Woohoooo!!

Education is never achieved by wise men. it is only believed to have been achieved by fools

StealthHacker

  • Hero Member
  • *****
  • Posts: 1019
  • Reputation: 41
  • Supreme Hacker
    • iNinjas
  • Computers: HP S2031 Windows 7 64 Bit Home Premium
  • iDevices: Jailbroken iPod Touch 5G iOS 6.0.1
Re: Data Values
« Reply #3 on: May 25, 2012, 08:20:29 pm »
Very useful *Hits that +1 button*
He who asks a question remains foolish for 5 minutes. He who doesn't ask a question remains foolish forever.

C0deH4cker

  • Hero Member
  • *****
  • Posts: 2849
  • Reputation: 129
  • I am leaving iNinjas. Contact me via email.
  • Badges:
  • iDevices: iPhone 4S 16gb Black (5.1.1), iPad 2 32gb White (5.0.1), iPod Touch 2G 8gb (4.2.1)
Re: Data Values
« Reply #4 on: May 25, 2012, 09:37:40 pm »
THANK YOU so much for explaining this C0deH4cker. So happy to read this (I swear).
I think I am a bit slow and got lost at the hex/binary conversions, but love the general tut.
Are "hexits" always double figures?
Thanks again man. Woohoooo!!
"hexits" are simply hex digits (a single number or letter A-F). It's just a term used to describe the digits in hex since they are not technically digits.

Don't like seeing ads? Click here to register!

FCKSHTUP

  • Full Member
  • ***
  • Posts: 179
  • Reputation: 14
  • If you're good at something, never do it for free.
  • Computers: macbook pro late 2011 (lion 10.7.2)
  • iDevices: ipod touch 4g 5.0.1, iPhone 3g 4.2.1 tmobile unlocked, iphone 4s 5.0.1 trying to unlock, ipod 4 5.1.1
Re: Data Values
« Reply #5 on: May 30, 2012, 02:15:45 am »
Nice tut, I i was getting confused with that a while back but now its clear
Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid. -Einstein

Breck15

  • Jr. Members
  • **
  • Posts: 58
  • Reputation: 5
  • CompTIA Net+ Certified, Microsoft Powerpoint Cert.
  • Computers: Win vista changed to win 7
  • iDevices: Ipod 2g, iphone 4g white
Re: Data Values
« Reply #6 on: May 30, 2012, 08:23:32 pm »
Ooo boy!! I love binary!! :D my favorite!!! And i just got CompTIA Net+ certified!!! Woop woop!
SHEIT HAPPENS!!

grinch

  • Administrator
  • Hero Member
  • *****
  • Posts: 1942
  • Reputation: 188
  • dIGITAL gRINCH
    • @DigitalGrinch
  • Badges:
  • iDevices: iPhone 3GS 4.3.3, HTC Evo V 4G ICS
Re: Data Values
« Reply #7 on: June 15, 2012, 10:57:53 am »
Nice work, some good foundations for programming here
Nice job explaining hex <-> decimal too

+1
If I help you or you appreciate my work, clicking that +1 button is the best thanks I could get.

My opinions are my own, you may agree or disagree with them, but they are only just that; opinions
For example: facebook is the microsoft of social networks

http://goo.gl/PiVjI

@DigitalGrinch
https://twitter.com/DigitalGrinch

I follow all iNinjas members back. PM me if I am not following you

grinch

  • Administrator
  • Hero Member
  • *****
  • Posts: 1942
  • Reputation: 188
  • dIGITAL gRINCH
    • @DigitalGrinch
  • Badges:
  • iDevices: iPhone 3GS 4.3.3, HTC Evo V 4G ICS
Re: Data Values
« Reply #8 on: June 15, 2012, 11:00:56 am »
Ooo boy!! I love binary!! :D my favorite!!! And i just got CompTIA Net+ certified!!! Woop woop!

0100001101101111011011100110011101110010011000010111010001110011001000000110010001110101011001000110010100100001

0010101100110001

For those who do not love binary:
(Congrats dude!)
(+1)

If I help you or you appreciate my work, clicking that +1 button is the best thanks I could get.

My opinions are my own, you may agree or disagree with them, but they are only just that; opinions
For example: facebook is the microsoft of social networks

http://goo.gl/PiVjI

@DigitalGrinch
https://twitter.com/DigitalGrinch

I follow all iNinjas members back. PM me if I am not following you

Ironman

  • Administrator
  • Hero Member
  • *****
  • Posts: 5152
  • Reputation: 252
  • Badges:
  • Computers: ASUS UL50VT
  • iDevices: iPhone 5, iPhone 4S, iPhone 4, iPhone 3GS
Re: Data Values
« Reply #9 on: June 16, 2012, 11:18:57 pm »
Very nice tut !! When I was in electronics/computer school back in the early 80's. One of the projects we had to do was build a binary clock from scratch. So I'm familiar with Hex and Binary and you presented it very well and simply. Great job!!
Click for How to Add Our Repo
If you're going to ask questions....
At least make them good ones.

Knowledge is the one thing that can never be taken from you

Don't like seeing ads? Click here to register!