Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

ASCII glyph values

Name: Anonymous 2008-03-22 0:27

Sup /prog/.

I need to get the acutal glyph value, not the ascii value, of a char in c++. Google isnt helping. Will you halp? What if i promise to read my SICP every day?

To clarify, if, for example, i want the value of the glyph for '2', i want the integer value 2, not its ascii decimal value of 50.

Name: Anonymous 2008-03-22 0:39

'2' - '0'

Name: Anonymous 2008-03-22 2:17

Ok, now I want to do the opposite; i get an integer, i then want to convert to its corresponding ascii glyph, then append to a string.

    //add 48 to get the ascii value of the integer (0 to 9)
    character = num_o + 48;

    result = static_cast<char>(character) + result;

Except the output of this is:
    ;6<

WTF??!?

Name: Anonymous 2008-03-22 2:18

That's quite possibly the easiest thing you could figure out by yourself.

Name: Anonymous 2008-03-22 2:21

static_cast<char>

....

Name: Anonymous 2008-03-22 2:29

Disregard that, I suck dicks. But now my output is "162". Sigh. Thats what I get for trying to be productive. (it should be 1061).

Name: Anonymous 2008-03-22 2:31

int main()
{
 
  string m, n, result = "";
  int index, num_m, num_n, num_o, difference, character;
  char cvalue;
  bool carry;

  cout << "Enter 2 positive integers: ";
  cin >> m >> n;
 
  //make the two strings equal in length by adding the correct amount of 0's to the shorter one
 
  if(m.length()> n.length())
  {
    difference = m.length() - n.length();
    do
      n = "0" + n;
    while(m.length() > n.length());
  } 
  else if(n.length() > m.length())
  {
    difference = n.length() - m.length();
    do
      m = "0" + m;
    while(n.length() > m.length());
  }
  else//do nothing
  {
  }
 
  cout << n << endl << m << endl;
  for(index = m.length()-1; index >=0; index--)
  {
    //convert the indexed value to a char, then static cast to an int, then subtract ascii'0' to give value
    cvalue = m[index];
    num_m = static_cast<int>(cvalue);
    num_m = num_m - 48;

    cvalue = n[index];
    num_n = static_cast<int>(cvalue);
    num_n = num_n - 48;
   
    //add the two values at the same index in m and n
    if (carry)
    {  
       num_m = num_m + 1;
    }  
    //add values
    num_o = num_m + num_n;
   
    //set the carry flag true, then set num_o to itself - 10 because the carry flag represents the 10 you subtract
    if(num_o >=10)
    { 
      carry = true;
      num_o = num_o - 10;
    }
    //add 48 to get the ascii value
    character = num_o + 48;

    result = (char)character + result;
    character = 0;
  }
 
  cout << result << endl;
  system("pause");
  return 0;
}

Name: Anonymous 2008-03-22 2:32

For those interested, I'm trying to add 2 positive integer values of arbitrary length.

Sorry to spam up /prog/ with my irrelevent shit.

Name: Anonymous 2008-03-22 2:35

result = static_cast<char>(character) + result;

What are you trying to do here? Append to a string or something? It doesn't work like that.

Name: Anonymous 2008-03-22 2:38

I was doing a fail append a character to a string. Changed to

result = (char)character + result;

Which is probably equally wrong.

Name: Anonymous 2008-03-22 3:15

you can't append to multibyte strings with +

Name: Anonymous 2008-03-22 3:19

oh I didn't see your other post, so your not using multibyte strings

Name: Julie Sussman 2008-03-22 3:27

>>1
Have you read SICP? It's all explained in there...

Name: Anonymous 2008-03-22 4:58

There's this little known function atoi()...

Name: Anonymous 2008-03-22 5:50

>>8
int alen = strlen(a);
int blen = strlen(b);
int len = max(alen,blen);
for(i=0;i<max;i++)
 c[i]=(a[i]+b[i]+carry)%10;
 carry = (a[i]+b[i])/10;
}

+
for(i=0;i<strlen(a)&&isdigit(a[i]);i++)
 a[i]-=48;

Name: Anonymous 2008-03-22 5:56

>>14
You even write it in K&R at some point.

Name: Anonymous 2008-03-22 7:22

>>16
Is that in any way related to the topic?

Name: Anonymous 2008-03-22 7:58

>>14
strtol fagot

Name: Anonymous 2008-03-22 8:18

some people shouldn't be programming

Name: Anonymous 2008-03-22 13:48

OP is the dumbest faggot ever

Also, "glyph value" doesn't make any sense.

Name: Anonymous 2008-03-23 1:16

>>17
Or is it just your way of saying, "I've read K&R"?

Name: Anonymous 2008-03-23 8:27

Prelude> read "2" :: Integer
2
it :: Integer
Prelude> show it
"2"
it :: String

Name: Anonymous 2008-03-23 11:24

>>8
String add(String a, String b) {
  return new BigInteger(a).add(new BigInteger(b)).toString();
}

Name: Anonymous 2008-03-23 14:52

boost::lexical_cast, motherfuckers.

Name: Anonymous 2008-03-25 8:24

>>23
BIG INTEGER IS BIIIIIIIIIIIIIIIG

Name: Anonymous 2008-03-25 9:48

>>25
[o]back to /b/, please[/o]

Name: Anonymous 2009-08-17 0:30

Lain.

Name: Anonymous 2010-11-15 6:46

Name: Anonymous 2011-02-03 1:30

Name: Anonymous 2013-09-01 14:34


However, the earliest attestable accounts of mathematical infinity come from Zeno of Elea (c. 490 BCE? – c. 430 BCE?), a pre-Socratic Greek philosopher of southern Italy and member of the Eleatic School founded by Parmenides. Aristotle called him the inventor of the dialectic. He is best known for his paradoxes, described by Bertrand Russell as "immeasurably subtle and profound".

Don't change these.
Name: Email:
Entire Thread Thread List